Solved

Stop asp.net page postback from javascript

Posted on 2006-10-27
2
976 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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