我有一个javascript来调用时启用文本框,我想在用户从下拉列表中选择值“Custom”时触发此代码,以便我可以显示/隐藏这些新文本框。
<asp:DropDownList ID="DateRangeDropDownList" runat="server" Enabled="False" **OnSelectedIndexChanged="EnableTextBoxes('SomeValue');"**>
<asp:ListItem>Some Value</asp:ListItem>
<asp:ListItem>Custom</asp:ListItem>
</asp:DropDownList>
但是当我运行这段代码时,我得到了
Too many characters in character literal
在上面一行,这让我想到,它是关于我从asp控件调用客户端脚本的方式。有人可以在这里指导我吗?
答案 0 :(得分:3)
您正在使用服务器端事件。
没有OnClientSelectedIndexChanged
事件,但您只需在标记中设置onChange
属性。
它将起作用,因为ASP:DropDownList
服务器控件在客户端上呈现为select
元素:
<asp:DropDownList ID="DateRangeDropDownList" runat="server" Enabled="False"
onChange="EnableTextBoxes('SomeValue');">
<asp:ListItem>Some Value</asp:ListItem>
<asp:ListItem>Custom</asp:ListItem>
</asp:DropDownList>
答案 1 :(得分:0)
OnSelectedIndexChanged
是服务器端事件,而不是Javascript事件
因此,代码被解析为服务器端C#代码,而不是客户端Javascript。
您正在寻找客户端onchange
事件。