user1565000
user1565000

Reputation: 11

Server Tag is not well formed?

Before adding style to paragraph it was working fine but if i add style i am getting error like server tag is not well formed.please check out my code

<p 
    title='<%# DataBinder.Eval(Container.DataItem, "Title") %>' 
    id="P1" 
    runat="server" 
    style="top:<%# DataBinder.Eval(Container.DataItem, "Tops") %>px; left:<%#DataBinder.Eval(Container.DataItem, "Lefts") %>px; font-size:15px; color:White;">
</p>

Upvotes: 1

Views: 2620

Answers (3)

Jeff Turner
Jeff Turner

Reputation: 1347

on server bound controls, if you want to use <%#whatever%> inside of a property they must have single quotes instead of double. ie:

<asp:Label id="lbl1" runat="server" Text='<%#Eval("myvalue")%>' />

or

<p id="p1" runat="server" style='background:<%#Eval("color")%>;'>stuff here</p>

Upvotes: 5

Fedor Hajdu
Fedor Hajdu

Reputation: 4697

Just use single quotes around your style tag so you avoid the collision with the double quotes in the Eval part.

style='top:<%# DataBinder.Eval(Container.DataItem, "Tops") %>px; left:%#DataBinder.Eval(Container.DataItem, "Lefts") %>px; font-size:15px; color:White;">'

Upvotes: 1

Ankur Ghelani
Ankur Ghelani

Reputation: 659

try this code:

<p 
    title='<%# DataBinder.Eval(Container.DataItem, "Title") %>' 
    id="P1" 
    runat="server" 
    style='top:<%# DataBinder.Eval(Container.DataItem, "Tops") %>px; left:<%#DataBinder.Eval(Container.DataItem, "Lefts") %>px; font-size:15px; color:White;'>
</p>

Upvotes: 0

Related Questions