Link to home
Start Free TrialLog in
Avatar of Abirami Rajendran
Abirami RajendranFlag for United States of America

asked on

Stop asp.net page postback from javascript

Here is my scenario

I have a asp:button and that has a server side click event. The page_load binds a javascript function as attribute for ‘onclick’. The javascript function has does some client side calculations and displays confirm message box. How do I stop the page from posting if the user hits cancel in the confirm box?


aspx
-- html
<asp:Button ID="btnSave" runat="server" CssClass="buttonpri" Text="Submit"></asp:Button>

--javascript
function doSubmit() {
// do client side calculations

var submit = confirm('<display calculated value>. Do you want to submit?')
if (submit)
{
//do page __postback
{
else
{
//dont submit
}

}

aspx.vb
--Page_Load event
btnSave.Attributes.Add("onclick", "javascript:doSubmit();")

-- onclick event
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
….
End sub
ASKER CERTIFIED SOLUTION
Avatar of avanishp
avanishp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Abirami Rajendran

ASKER

Thanks! it Worked.