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 6248295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:01:52+00:00 2026-05-24T13:01:52+00:00

When you attach a client-side click event via jQuery to an ASP.NET button do

  • 0

When you attach a client-side click event via jQuery to an ASP.NET button do you then lose the ability to do a postback? I merely need to do some jQuery prior to the server-side stuff happening and it seems to be interrupting this process.

 $('[id$="btnDisableAlarms"]').click(function () {
            var commentValue = $('[id$="txtComment"]').val();
            if (commentValue == "") {
                // add red border (CSS)
                $('[id$="txtComment"]').addClass("redCommentError");
            }
            return;

        });

The button is wired up with a click event but the browser doesn’t budge.

 btnDisableAlarms.Click+=new EventHandler(btnDisableAlarms_Click);

 public void btnDisableAlarms_Click(object sender, EventArgs e)
    {
        Response.Write("Still able to manage a postback from server");
    }
  • 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-05-24T13:01:54+00:00Added an answer on May 24, 2026 at 1:01 pm

    The problem is that your jQuery click handler is overwriting the click handler that ASP assigns to the button. You could do something like:

    $('[id$="btnDisableAlarms"]').each(function (index, button) {
        var oldClickHandler = button.onclick;
        $(button).click(function () {
            // Do your stuff
            oldClickHandler();
        });
    });
    

    That might not be the right syntax for caching the old click handler, but it would be something similar to that.

    Edit: Actually it would be safer to preserve the context and the click event, something like:

    $('[id$="btnDisableAlarms"]').each(function (index, button) {
        var oldClickHandler = button.onclick;
        $(button).click(function (clickEvent) {
            // Do your stuff
            oldClickHandler.call(button, clickEvent);
        });
    });
    

    This ensures that if the old click handler uses this or tries to access the click event that triggered it, it’ll still work properly.

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

Sidebar

Related Questions

I attach a click handler to a button on my page. Is there anyway
I want to attach a 'click' event handler to the first child of an
Is there way to attach client side SSL file (.pfx) file in WCF binding?
I'm trying to debug Sitecore 6 ASP.NET code using Visual Studio 2008 (Windows Server
I'd like to catch all client-side JavaScript errors on our site and log them.
I have written some JavaScript to do client-side validation. If I press F5 to
I don't have access to the actual asp.net server tag itself, so I need
I am a perl developer that has never went into the client side programming
Let's say I attach a javascript change event handler to a select element, something
I'm writing an ASP.NET 3.5 web application. There is a rather complex input form

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.