Calling a javascript as an event handler for an asp.net server control

hi,
This is kind of strange to me.. may be im missing something here.. i have a asp.net 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 asp.net) 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?
jyotishbAsked:
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>

-tushar
0
 
Chirag1211Commented:
Instead try the following code on codebehind file in the Page_Load() event:

TextBox2.Attributes.Add("OnTextChanged","foo();");

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

Regards,

Chirag Patel
0
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.