C# 服务器标签格式不正确错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15278616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:15:12  来源:igfitidea点击:

The server tag is not well formed error

c#asp.net

提问by calypso

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

我写了这段代码。该代码包含预期的 runat="server" 属性,但它给了我以下错误消息:error on hiddenfieldpart.

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

采纳答案by Adil

You could not use double quotes within double quotes so use combination of singleand doublequotes.

您不能在双引号内使用双引号,因此请使用singledouble 的组合quotes

Change

改变

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

To

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

回答by dave823

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

在使用 eval scriptlet 时尝试使用单引号而不是双引号,如下所示:

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

我真的不明白为什么需要这样做,但这就是有效的原因。

回答by Roshna Omer

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

由于引号,我遇到了同样的错误,这就是我修复我的方法

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