来自ASP控件的客户端javascript调用抛出“字符文字中的字符过多”错误!

时间:2010-01-03 20:18:46

标签: asp.net javascript drop-down-menu server-side client-side

我有一个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控件调用客户端脚本的方式。有人可以在这里指导我吗?

2 个答案:

答案 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事件。