[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 812
  • Last Modified:

No PostBack on Asp.Net button

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:

button...
<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.
0
russomr
Asked:
russomr
1 Solution
 
KarinLoosCommented:
as far as I know, you cannot prevent an asp button from doing a postback
0
 
TimCotteeCommented:
Hi russomr,

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

The return false will prevent the postback from happening.

Tim Cottee
0
 
russomrAuthor Commented:
That's the ticket!  Thank you.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now