No PostBack on Asp.Net button

Posted on 2006-04-20
Last Modified: 2012-05-05
I realize this is a common question, however I still can't seem to find a good answer.

I have the following ASP.Net C# code:

<asp:Button id="btnCalculate" runat="server" Text="Calculate" />

page load code...
btnCalculate.Attributes.Add("onclick", "JavaScript:calculateForm();");

How do I get the button not to post back?  I notice AutoPostBack=false is not an option.  I realize I can turn it into an HTML button, but I'm trying to avoid that for other reasons.
Question by:russomr
    LVL 13

    Expert Comment

    as far as I know, you cannot prevent an asp button from doing a postback
    LVL 44

    Accepted Solution

    Hi russomr,

    btnCalculate.Attributes.Add("onclick", "JavaScript:calculateForm();return false;");

    The return false will prevent the postback from happening.

    Tim Cottee

    Author Comment

    That's the ticket!  Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    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…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now