Running client script before a postback initated by an asp button

M

Marshal Antony

Charlie,

put this javascript function on the client side of your aspx page
<script>
function confirmSubmit() { var sure=confirm("Are you sure you wish to
continue?");
if (sure) return true ; else return false ; }</script>

and call it from the onclick event of your server control for Save say
BtnSave.
You can type it in the tag itself
onclick="return confirmSubmit();"
or
in the Page_Load
BtnSave.Attributes.Add("onclick","return confirmSubmit();");

Regards,

Marshal Antony

http://dotnetmarshal.com
 
M

Marshal Antony

If you make a regular INPUT button (HTML control) and make it
RUNAT="SERVER" you can put that
javascript function call in the tag itself for the event you want.But this
may not be the case with Server controls.
For eg : Imagebutton's OnClick event is meant for the Server side event
handling.
There might be exceptions which I am not sure.
Hope this helps.
Regards
Marshal Antony
http://dotnetmarshal.com
 
C

Charlie@CBFC

Hi:

when the user selects the save button (asp control) to intiate a postback, I
would like to pop up a javascript alert box to confirm if he really wants to
save. If he selects no from alert dialog, I would like to cancel the
postback. How do you do this?

Thanks,
Charlie
 
C

Charlie@CBFC

Thanks! That worked well. However, I was only able to make it work using
add.attributes in server code. I tried adding "onclick="return
confirmSubmit();" in the HTML tag, but got errors. Is it possible to call a
client script function in HTML tag like an ordinary HTML control? HTML
Intellisense shows an on_click handler for asp button, but can't figure out
how to wire it up.

Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top