Calling a javascript as an event handler for an server control

This is kind of strange to me.. may be im missing something here.. i have a textbox control, and i m trying to associate a javascript function to OnTextChange event, but its giving me a strange error.. but when i  associate the same javascript function with onKeyUp event ( which doesnt even shows as a valid event in it works fine..

<asp:TextBox ID="TextBox2" runat="server" onKeyUp="foo();"></asp:TextBox>  (works fine, but validation warning)
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="foo();"></asp:TextBox> (doesnt work error : Invalid expression term ')'     )

any idea?
Who is Participating?
tusharashahConnect With a Mentor Commented:
OnTextChange is a ASP.Net server side event.. to call the change event at client side you'll need to use OnChange event of JavaScript..

<asp:TextBox ID="TextBox2" runat="server" OnChange="foo();"></asp:TextBox>

Instead try the following code on codebehind file in the Page_Load() event:


Also add the javascript function foo() on the aspx page in the script tag.


Chirag Patel
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.