Ask a Question related to ASP.NET General, Design and Development.
-
Bob #1
Re: cancelling a postback on a button with javascript
Chris:
Try using the onSubmit event of the Form element to cancel the submission,
as opposed to the onClick event.
<script language=javascript>
function DoSubmit()
{
if (confirm("Sure?"))
{
return true;
}
else
{
return false;
}
}
</script>
<form method=post onSubmit=return DoSubmit();>
Returning false will stop the form from posting.
HTH
--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***
"Chris" <chrisb@papex.com> wrote in message
news:13f701c34f83$bbd2cb90$3501280a@phx.gbl...> Does any one know a simple way to cancel a serverside
> postback on a button in asp.net using javascript? Right
> now, I indicate that I want the the button to postback to
> the server and be handle by a certain event. However, I
> also want to the give the user an opportunity to cancel
> the request. Right now, I have both an onclick event for
> the button which uses the confirm function in javascript:
> i.e. (confirm('are you sure you want to delete?');
>
> The problem. Regardless if the "ok" or "cancel" buttons
> are pressed, the postback event for the button is fired.
> Looking at the source code I can see why. My onclick
> function is processed first, and then the ___dopostback
> ('mybutton',''); is fired. How can I stop this from
> happening?
>
> Any thoughts or suggestions would be greatly appreciated.
>
> Thanks,
>
> Chris...
Bob Guest
-
custom web control +client-side javascript + postback
Hello, I am trying to create a new Web Control (ASP.NET 1.1) that contains among other textboxes. The content of these textboxes (runat=server)... -
DataGrid contains no data after postback of edit button click...
This is specifically what is going on in my application:... -
serverside button and javascript
You have to add a return to the code the Alex gave you deleteQuote.Attribute.Add("onclick", "return(confirm_delete());") -
button created using attributes.add to run script in html...fires with each page postback
Hi, I have the following script in an aspx html: <script language="javascript"> function pop_window() { var confirmWin = null; confirmWin =... -
JavaScript Access to Button in form tags (webcontrol or html button)
Hello, I have a button called LoadBtn, which exists in <form name="Form1" runat=server></form> tags. I then have javascript loaded outside of... -
Chris Barrow #2
Re: cancelling a postback on a button with javascript
Hi Bob,
Unfortunately, the onsubmit method doesn't get invoked when using a
standard postback. For example: Form1.submit(), which is part of the
___dopostack function generated by asp.net doesn't invoke the onsubmit()
method. Too damn bad though, it was a good idea, and I thought I had my
problem solved. Thanks for the help...
Chris...
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Chris Barrow Guest
-
Elliot M. Rodriguez #3
Re: cancelling a postback on a button with javascript
Still solved - change the button from a WebControl to an HTMLInputControl
and specify runat=server. That should do the trick.
--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***
"Chris Barrow" <chrisb@papex.com> wrote in message
news:Opbtro7TDHA.2316@tk2msftngp13.phx.gbl...> Hi Bob,
>
> Unfortunately, the onsubmit method doesn't get invoked when using a
> standard postback. For example: Form1.submit(), which is part of the
> ___dopostack function generated by asp.net doesn't invoke the onsubmit()
> method. Too damn bad though, it was a good idea, and I thought I had my
> problem solved. Thanks for the help...
>
> Chris...
>
>
>
> *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
> Don't just participate in USENET...get rewarded for it!
Elliot M. Rodriguez Guest
-
Chris Barrow #4
Re: cancelling a postback on a button with javascript
Hi Elliot,
It worked! Thank you. I actually had the button declared as an
HTMLInputButton within the vb code-behind, but on the .aspx side as
<input type="button", rather than "submit". Changing the type of button,
caused the "DoSubmit" function to be invoked when the button was
clicked. Pressing the cancel button in the confirm dialog box cancels
the postback.
Thanks again for your help, and sorry for calling you Bob! I must have
been drinking too much mountain dew the first time I replied to you.
Chris...
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Chris Barrow Guest
-
S. Justin Gengo #5
Re: cancelling a postback on a button with javascript
Just as a note, you can stop post back from any type of button if you just
use an if-then javascript for the confirmation:
MyButton.Attributes.Add("onClick", "javascript:if(!confirm('" &
MessageToDisplay & "')) return false;")
--
S. Justin Gengo, MCP
Web Developer
Free code library at:
[url]www.aboutfortunate.com[/url]
"Out of chaos comes order."
Nietzche
"Chris Barrow" <chrisb@papex.com> wrote in message
news:OFXagnEUDHA.2252@TK2MSFTNGP12.phx.gbl...> Hi Elliot,
>
> It worked! Thank you. I actually had the button declared as an
> HTMLInputButton within the vb code-behind, but on the .aspx side as
> <input type="button", rather than "submit". Changing the type of button,
> caused the "DoSubmit" function to be invoked when the button was
> clicked. Pressing the cancel button in the confirm dialog box cancels
> the postback.
>
> Thanks again for your help, and sorry for calling you Bob! I must have
> been drinking too much mountain dew the first time I replied to you.
>
> Chris...
>
>
> *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
> Don't just participate in USENET...get rewarded for it!
S. Justin Gengo Guest



Reply With Quote

