tags:

views:

42

answers:

2

I have this div that's got a style attribute..In that I am setting it's background image by calling a function from code behind..

<div id="id1" style = "background-image: url(<%=GetImage()%>);"></div>

now when I add runat="server" attribute in this div..it shows the Image path as method name itself and not http://localhost/myweb/images/image.jpg

when I remove runat..image path displays alright..Isn't the runat supposed to be there because it's got inline aspx tag ??? I am confused.

+2  A: 

No, runat is not supposed to be there. Since you do not need to access this control on server side, you do not need it.

Pranav Kaushik
but method's gonna run at server side only..this is what is confusing me
Serenity
so u mean if I add some attribute to this div in code behind like .. "id1.Attributes.Add(..); " ...only then I need to give runat..right ??
Serenity
@Happy Soul yes, you only need `runat="server"` if you need programmatic access to the control from *code-behind*. Remember, the simple fact of it being an `aspx` file means it *will* be processed by the ASP.NET engine, so `<% %>` tags *will* be processed.
AakashM
+3  A: 

Runat controls whether a control instance will be created server side. Dynamic injection directives such as <%=%> are always processed whether runat is set or not.

vc 74
umm ok...thanks
Serenity