?
Solved

Stop asp.net page postback from javascript

Posted on 2006-10-27
2
Medium Priority
?
979 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

771 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