简体   繁体   中英

The server tag is not well formed error

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>                  

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" />

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.

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

    OnClientClick='<%# "CallToFunc("+ Eval("Val") + 
    ",\"" + Eval("StringVal")  + "\");return false;"

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 eg like this:

<!-- asp.Label   runatX="server" ... -->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM