Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The server tag is not well formed error

Tags:

c#

asp.net

I wrote this code. The code contains the expected runat="server" attribute, but it is giving me this error message: error on hiddenfield part.

 <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:HiddenField ID="HiddenField1" Value="<%#Eval("Path")%>" runat="server" />
        <img alt="image" style="text-align: center" src="<%#Eval("Path")%>" /><asp:CheckBox
            ID="CheckBox1" runat="server" />
        <br></br>
    </ItemTemplate>
</asp:Repeater>                  
like image 835
calypso Avatar asked Mar 07 '13 18:03

calypso


4 Answers

You could not use double quotes within double quotes so use combination of single and double quotes.

Change

<asp:HiddenField ID="HiddenField1" Value="<%#Eval("Path")%>" runat="server" />

To

<asp:HiddenField ID="HiddenField1" Value='<%#Eval("Path")%>' runat="server" />
like image 140
Adil Avatar answered Nov 20 '22 10:11

Adil


Try using single quotes instead of double quotes when using an eval scriptlet, like this:

 <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:HiddenField ID="HiddenField1" Value='<%#Eval("Path")%>' runat="server" />
        <img alt="image" style="text-align: center" src='<%#Eval("Path")%>' /></a><asp:CheckBox
            ID="CheckBox1" runat="server" />
        <br></br>
    </ItemTemplate>
</asp:Repeater>   

I really don't understand the reasoning why this is required, but that is what works.

like image 20
dave823 Avatar answered Nov 20 '22 10:11

dave823


You cannot have runat inside of a html comment.

(Not the problem of this question, but it matches the title of this question)

Suppose you have an ASP control that you want to "comment out", then you might end up with a page that cannot show at all, with, if you are lucky, the "server tag is not well-formed" exception, or with a simple 404-not found status code.

Fix: change the runat e.g. like this:

<!-- asp.Label   runatX="server" ... -->
like image 1
Roland Avatar answered Nov 20 '22 10:11

Roland


I had the same error because of quotes and this is how I fixed mine

    OnClientClick='<%# "CallToFunc("+ Eval("Val") + 
    ",\"" + Eval("StringVal")  + "\");return false;"'
like image 1
Roshna Omer Avatar answered Nov 20 '22 08:11

Roshna Omer