English 中文(简体)
Client Side javascript call from ASP control throws "Too many characters in character literal" error!
原标题:

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?

最佳回答

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>
问题回答

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签