[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Stop asp.net page postback from javascript

Posted on 2006-10-27
2
Medium Priority
?
993 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:sansoftura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
avanishp earned 1000 total points
ID: 17824769
use

btnSave.Attributes.Add("onclick", "return doSubmit();")


and in javascript function

function doSubmit() {
// do client side calculations

var submit = confirm('<display calculated value>. Do you want to submit?')
if (submit)
{
 return true
}
else
{
 return false
}

}
0
 
LVL 6

Author Comment

by:sansoftura
ID: 17825657
Thanks! it Worked.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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