Tuesday 19 March 2013

Set html body background image using asp.net


Introduction:
I have scenario that I have admin setting for back ground. Whatever image I uploaded. I want to set dynamic background image on body of form.

Approach
 My approach is to get image from database with absolute path and assign style of body tag of form

<body runat="server" id="BodyTag">

In your code behind, do this (C#):
I have data table with uploaded image name. I have made absolute path available for image.
String myImagePath = "../Images/Upload/"+dt_Background.Rows [0]["ImageURL"].ToString ();

BodyTag.Style.Add ("background-image", "url("+myImagePath+")");




 In body tag with image path “~/Images” is not working.









No comments:

Post a Comment