Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:49:59+00:00 2026-06-15T10:49:59+00:00

Like many others, I’m trying to invoke a .NET control’s server-side event from JavaScript.

  • 0

Like many others, I’m trying to invoke a .NET control’s server-side event from JavaScript.

Specifically, I want to fire the TextChanged event on a TextBox named txtSearch. Therefore, I’m looking to reach the following event from client-side:

protected void txtSearch_TextChanged(object sender, EventArgs e)

Having read many answers on SO (for example here and here) I have the following JavaScript:

__doPostBack('ctl00$ctl00$Container$Main$txtSearch', 'TextChanged');

But the server-side event never fires.

I’ve tried numerous permutations: with the AutoPostBack true and false, with and without the event declared in the server-side instructions on the ASPX (i.e. OnTextChanged=””), with the EventValidation turned off in the page declaration, using the ClientID rather than the UniqueID in the EVENTTARGET parameter… but the event is still never fired.

A couple of other points

  • the txtSearch button control is also the trigger for an UpdatePanel, in case that matters.
  • I’m converting existing code, of which there’s quite a lot, and am looking for something I can drop onto each page rather than converting the code-behind events to PageMethods.

Can anyone tell me what more I need to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:50:00+00:00Added an answer on June 15, 2026 at 10:50 am

    I’ve tried this, and it works for me:

    <asp:TextBox runat="server" ID="txtSearch" OnTextChanged="txtSearch_TextChanged"></asp:TextBox>
    <input type="button" value="submit" onclick="<%= GetOnChangedScript() %>" />
    

    The server side asp:TextBox, and the client side input which fires __doPostBack on click. The __doPostBack script is generated through PostBackOptions:

    protected string GetOnChangedScript()
    {
        var options = new PostBackOptions(txtSearch, string.Empty);
        options.AutoPostBack = true;
        options.RequiresJavaScriptProtocol = true;
        var script = Page.ClientScript.GetPostBackEventReference(options);
        return script;
    }
    

    The txtSearch_TextChanged event handler fires when the value of text box is changed, and the submit button is clicked.

    But note, for controls like TextBox the text is stored in the viewstate; the new text entered by the user stores in the form data. When the TextBox load the viewstate data, it gets the old value. This is compared with the new value that comes in the form. If the values are different, the TextChanged event is fired. If no, the event handler won’t be fired. This is the reason for the Page_Load event get fired (postback occured), but txtSearch_TextChanged didn’t fire due to the value of the TextBox didn’t change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a little client-server script like many others that I've done
Trying to bend by head around Javascript's take on OO...and, like many others, running
Like many others on this site I am considering a move to ASP.NET MVC
I'm really new in Android Development and, like many others, I'm trying desperately to
Like many others, I've been killing braincells trying to get oauth to work on
Like many others, I am trying to draw 3D objects (using GLSurfaceView) on camera
Like many others Knockout developers before me, I encountered a slow running script warning
I, like many others, love Eclipse as my ide of choice, and because of
I am creating dynamic TextFields in actionscript 3.0. Like many others, my text disappears
This sounds like a problem many others have posted about, but there's a nuance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.