什么意思是“服务器标签格式不正确”,这个按钮会发生什么

What mean "the server tag is not well formed", what happen with this button?

本文关键字:什么 按钮 意思是 服务器 标签 格式 不正确      更新时间:2023-09-26

这是我的按钮:

<asp:LinkButton ID="lnkButton" 
    OnClientClick="showEnroll(this,true,'<%# Eval("EventId") %>'); return false"      
    runat="server" CommandArgument='<%# Eval("EventId") %>'  />

这是错误:"服务器标记格式不正确"

这意味着标记无效,这是因为内联数据绑定表达式。像这样的东西应该更好用:

OnClientClick='<%# string.Format("showEnroll(this, true, ''{0}''", Eval("EventId")) %>'

注意:我尚未验证上述代码。它旨在说明一个概念,可能需要调整。

在您的绑定中(即 RowDataBound网格视图),添加如下逻辑:

// Attempt to find the control
var theLinkButton = e.Row.FindControl("lnkButton") as LinkButton;
// Only try to use the control if it was actually found
if(theLinkButton != null)
{
    // Grab the event ID from wherever here
    // Set the OnClientClick attribute here
    theLinkButton.Attributes.Add("onClientClick", 
        "showEnroll(this,true,'" + theEventId.ToString() + "'); return false");
}