473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Running client script before a postback initated by an asp button

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
Nov 18 '05 #1
3 2141
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


"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
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
"Marshal Antony" <ma***********@yahoo.com> wrote in message
news:uc****************@tk2msftngp13.phx.gbl...
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


"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
> 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
>
>


Nov 18 '05 #3
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

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
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
"Marshal Antony" <ma***********@yahoo.com> wrote in message
news:uc****************@tk2msftngp13.phx.gbl...
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


"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
> 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
>
>



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Moore | last post by:
Can an asp.net button that is a server side control call a client side java function when the button is clicked? If so, please provide example.....thanks.,
1
by: Jim Hammond | last post by:
I can get data from a client-side assembly to the server in two manual steps, but I need to be able to do it in one step. Step 1: The user presses the manually coded "Step 1" button, which calls...
4
by: Guadala Harry | last post by:
Suppose I have a hyperlink that, when clicked, executes a JavaScript function on the client. Separately I have a button that, when clicked, causes a post back and executes a server-side function,...
1
by: Jordan | last post by:
I'm trying to initiate Postback from client-side script, and here's what I have that doesn't work: I have an <asp:Button> on the same page named btnSave that the user can click (its functionality...
1
by: Donal McWeeney | last post by:
Hi, Any pointers to manipulating client side validation being performed. For example I have a custom control that does a postback to the server - and I dont want validation to be performed...
5
by: Jerry Camel | last post by:
Trying to implement the following: Users is logging in They enter theire username and password and click a login button The page should then display an activity indicator (animated gif) and then...
2
by: COHENMARVIN | last post by:
I am working on an application where the user enters info into a multiline textbox. The info is Stylesheet tags that he wants web pages to use. Basically he would be entering a stylesheet into...
14
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So,...
8
by: MAX2006 | last post by:
Hi, I am doing some client side javascipt work. I have a handler for window.onUnload event and within the code; I need to know the name of the asp.net button caused the postback. How can I do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.