asp.net错误为“;文字字符“”中的字符太多;

asp.net error as "Too many characters in character literal"

本文关键字:字符 太多 net 错误 asp 文字      更新时间:2023-09-26

我正在对DropDownList的索引更改调用javascript,我按照以下进行操作

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="toggleVisibility('Button1');">

我在编译过程中得到了错误,因为上面的代码行

Too many characters in character literal

有人能帮我解决这个问题吗?

OnSelectedIndexChanged是服务器端事件,

如果您想在客户端切换可见性,则需要设置OnClientClick并设置AutoPostBack="false"

对于服务器端

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="toggleVisibility">
protected object toggleVisibility(object sender, EventArgs e)
{
   Button1.Visible = !Button1.Visible;
}

因此,对于事件,您需要使用具有特定签名的方法名称,该签名由事件类型定义。这是object sender, EventArgs e

编辑

DropDownList没有名为OnClientClick的属性,因此您需要将其添加到codeehind 中

DropDownList1.Attributes.Add("onchange","toggleVisibility('Button1');");