Serenity
Serenity

Reputation: 5098

Question about inline aspx tags

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.

Upvotes: 1

Views: 190

Answers (2)

Pranav Kaushik
Pranav Kaushik

Reputation: 203

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.

Upvotes: 2

vc 74
vc 74

Reputation: 38179

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.

Upvotes: 3

Related Questions