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

  • Home
  • SEARCH
  • 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 8152553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:44:46+00:00 2026-06-06T15:44:46+00:00

When using a standard asp:Button component, it is necessary to use the following technique

  • 0

When using a standard asp:Button component, it is necessary to use the following technique to cancel an automatic postback (or make a postback conditionally):

  • Specify the client-side operations via the Button.OnClientClick property;

  • Implement a logic that returns a Boolean value that indicates whether or not a postback should performed.

The following does not cancel a postback (despite of the “OnClientClickHandler” method returns “false”):

<asp:Button ID="btn" runat="server" OnClientClick="OnClientClickHandler();" />

function OnClientClickHandler() {
    return false;
}

The following implementation does:

<asp:Button ID="btn" runat="server" OnClientClick="return OnClientClickHandler();" />

It looks like that this behavior is caused by specifics of the JavaScript code scope. Anyway, I am interested in the low-level implementation details of this scenario.

Why doesn’t the first implementation (where there is no “return” operator before the “OnClientClickHandler” method call) work?

  • 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-06T15:44:49+00:00Added an answer on June 6, 2026 at 3:44 pm

    The reason why you need to add return is because returning false from an event handler is the way to cancel the default behavior (in this case, submit the form).

    Another way to do the same is executing event.prefentDefault()

    OnClientClick="OnClientClickHandler();" would be equivalent to

    function onclick(){
        OnClientClickHandler();
    }
    

    while OnClientClick="return OnClientClickHandler();" would be equivalent to

    function onclick(){
        return OnClientClickHandler();
    }
    

    Do you see the difference? In the first case you’re just executing the function, but returning nothing.

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

Sidebar

Related Questions

I'm using a standard asp.net menu in an asp.net 4.0 web application. To clarify,
I have an ASP.NET 3.5 Web Site using the standard SQL Membership Provider. The
I'm using ASP.NET WebForms. I'm using the standard sitemap provider. Home > User >
We have a couple ASP MVC websites just using the standard VS templates default
Using the standard ASP.NET login control, I'm trying to get it to deny me
I'm using the standard asp:Login control, and we have a user who recently changed
We have a data driven ASP.NET website which has been written using the standard
I'm using a standard form rather than an ASP.Net form and posting it so
I'm using standard ASP.NET and a Web.sitemap file which describes the navigation structure of
I am having trouble defining bindings using ninject. I am in a standard ASP.NET

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.