Abirami Rajendran
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("on click", "javascript:doSubmit();")
-- onclick event
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
….
End sub
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("on
-- onclick event
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
….
End sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER