What's the right way to add a popup Confirm in ASP.Net 1.1??

G

Guest

I need to get the user to confirm a button push/postback with a popup from
the browser, in ASP.NET 1.1. What's the right way to wire that up?? Thanks
 
M

Mark Rae

I need to get the user to confirm a button push/postback with a popup from
the browser, in ASP.NET 1.1. What's the right way to wire that up??
Thanks

MyButton.Attributes.Add("onclick", "return confirm('Are you sure?');");

When you upgrade to ASP.NET 2, you can use the OnClientClick tag of the
<asp:Button> control.
 
M

Masudur

Hi Mark Rae

Well I am not an expart of this things. But you see Asp.net 2.0 is
giving you an opportunity to specify client side code in
"OnClientClick" property of asp.net 2.0 Button or Image Button.

So its better to use this property very often. But you see if your
button acts differently when you post back a page, and you need to bind
different onclick client function depending on context. In that case
you need to use Button.Attributes.Add("onclick","function();"); to make
it work the way you want.

If you are using a button which always serve one purpose, that is
confirm javascript dialog. In asp.net 2.0 I would use the OnClientClick
property in the designer to specify my client side code.

Md. Masudur Rahman
www.kaz.com.bd
KAZ Software Ltd.
Software outsourcing made simple...
 
H

Hans Kesting

ChrisA said:
MyButton.Attributes.Add("onclick", "return confirm('Are you sure?');");

When you upgrade to ASP.NET 2, you can use the OnClientClick tag of the
<asp:Button> control.

For linkbuttons, use

MyLinkButton.Attributes.Add("onclick", "if(!confirm('Are you sure?'))
return false;");

The reason: asp.net adds it's own "onclick" javascript code to that
linkbutton, which doesn't get run when you use the 'return confirm'
version. And for the same reason, don't forget the closing ";" after
the javascript code!

Hans Kesting
 
M

Mark Rae

Well I am not an expart of this things. But you see Asp.net 2.0 is
giving you an opportunity to specify client side code in
"OnClientClick" property of asp.net 2.0 Button or Image Button.

Did you actually read my reply? If not, please read it.

And then read it again.
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top