Calling a javascript as an event handler for an server control

Posted on 2007-08-12
Last Modified: 2013-11-26
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?
Question by:jyotishb
    LVL 18

    Accepted Solution

    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>

    LVL 9

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now