我在DropDownList的索引更改上调用javascript,我按照以下方式执行
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="toggleVisibility('Button1');">
我在编译期间遇到上述代码行
的错误Too many characters in character literal
有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
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的属性,因此您需要在codebehind中添加它
DropDownList1.Attributes.Add("onchange","toggleVisibility('Button1');");