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>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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.

Method 3

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

Method 4

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

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x