views:

220

answers:

2

I have a javascript to enable text boxes when called, I want to trigger this code when a user picks value "Custom" from a dropdownlist, so that I can display/Hide these new textboxes.

<asp:DropDownList ID="DateRangeDropDownList" runat="server" Enabled="False" **OnSelectedIndexChanged="EnableTextBoxes('SomeValue');"**>
                        <asp:ListItem>Some Value</asp:ListItem>
                        <asp:ListItem>Custom</asp:ListItem>
                    </asp:DropDownList>

but when I run this code I get

Too many characters in character literal

at the above line, which makes me think, its something about the way I am calling a client side script from an asp control. Can someone guide me here?

A: 

OnSelectedIndexChanged is a server-side event, not a Javascript event.
Therefore, the code is parsed as server-side C# code, not client-side Javascript.

You're looking for the client-side onchange event.

SLaks
+1  A: 

You are using the server-side event.

There is not an OnClientSelectedIndexChanged event, but you can simply set an onChange attribute in your markup.

It will work since the ASP:DropDownList server controls are rendered as a select element on the client:

<asp:DropDownList ID="DateRangeDropDownList" runat="server" Enabled="False" 
    onChange="EnableTextBoxes('SomeValue');">
    <asp:ListItem>Some Value</asp:ListItem>
    <asp:ListItem>Custom</asp:ListItem>
</asp:DropDownList>
CMS