Spartan
Spartan

Reputation: 65

aspx button prevent postback onclick (c#)

The code below shows some HTML with a <asp:Button> element.

<asp:Button ID="CalculateG481" runat="server" Text="Calculate" OnClick="CalculateG481_Click" />

This calls the function CalculateG481_Click but then posts back.

I have tried using OnClientClick="return false" but this simply prevents the button from executing CalculateG481_Click

I have also tried OnClick="CalculateG481_Click; return false;" as well to no avail.

EDIT: CalculateG481_Click is a C# Codebehind function.

Upvotes: 0

Views: 1345

Answers (1)

Win
Win

Reputation: 62300

The way you are doing is really strange - you cannot call Server-Side Button Event from Client-Side JavaScript.

You can either use regular input html tag with pure Client-Side calculation or Server Button Control with Ajax based on your requirement.

Easiest way is to use Ajax UpdatePanel, and place everything inside it.

Upvotes: 1

Related Questions