473,480 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Confirm box in .NET

I have scoured the web looking for an example of how to do a javascript confirm box in .NET.

Is there any way to do it?

Thanks.
Nov 18 '05 #1
10 2079
Hi Mike,

Regarding the issue, we can call window.confirm method in client side
script. For example:

if(window.confirm("Are you sure that you want to post data back to the
Server?"))
{
}
else
{
}

Does this answer your question?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Thanks for the answer, but how do I do it?

Is this a javascript deal or does it live in my code behind page?

How do I deal with this in my code behind page?

Would it be possible for you to put up a code snippet for me? Basically I have a delete button and I am trapping the click in the
code behind page, and I want the user to confirm.

Thanks.

"[MSFT]" <lu******@online.microsoft.com> wrote in message news:Bz*************@cpmsftngxa10.phx.gbl...
Hi Mike,

Regarding the issue, we can call window.confirm method in client side
script. For example:

if(window.confirm("Are you sure that you want to post data back to the
Server?"))
{
}
else
{
}

Does this answer your question?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
For showing message box in ASP.NET, you need to use client side scripts
only. You can use registerstartupscript or registerclientscript method to
register your client scripts in your form. In the client script you can use
window.confirm to show message box with ok/cancel button. Another option for
showing message box in ASP.NET is, by using free messagebox control which is
available at following location which you can download and use it. Check out
this url's for more details.

www.extremeexperts.com

or
http://www.microsoft.com/india/msdn/articles/119.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Mike Malter" <mi********@nospam.com> wrote in message
news:es*************@TK2MSFTNGP10.phx.gbl...
I have scoured the web looking for an example of how to do a javascript confirm box in .NET.
Is there any way to do it?

Thanks.

Nov 18 '05 #4
Hello Mike,
I have scoured the web looking for an example of how to do a
javascript confirm box in .NET.


control.Attributes.Add("onClick", "return confirm('Your Message');");

where control is the control you want the confirm box attached to. Keep in mind that this will not postback unless the user selects OK.

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #5
Matt,

This looks like what I am after, I'll try it. Thanks alot. Also, thanks to the others who answered here too.
"Matt Berther" <mb******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Mike,
I have scoured the web looking for an example of how to do a
javascript confirm box in .NET.
control.Attributes.Add("onClick", "return confirm('Your Message');");

where control is the control you want the confirm box attached to. Keep in mind that this will not postback unless the user

selects OK.
--
Matt Berther
http://www.mattberther.com

Nov 18 '05 #6
I think Matt provide the right sample. You may refer to it.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7

"Matt Berther" <mb******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Mike,
I have scoured the web looking for an example of how to do a
javascript confirm box in .NET.
control.Attributes.Add("onClick", "return confirm('Your Message');");

where control is the control you want the confirm box attached to. Keep in mind that this will not postback unless the user

selects OK.
--
Matt Berther
http://www.mattberther.com

For a regular button this will work, for a linkbutton you will need

control.Attributes.Add("onClick", "if (!confirm('Your Message')) return false;");

because asp.net will add it's own onclick handler after this, to get the postback
to work. That's why you *need* the closing ";" here.

Hans Kesting

Nov 18 '05 #8
Guys,

When I do this I get the following compiler error:

C:\Projects\SSSC\Cheese\wwwroot\ManageBrand.aspx.c s(51): Invalid token '(' in class, struct, or interface member declaration

My code is as follows:
protected System.Web.UI.WebControls.Button bDelete;
bDelete.Attributes.Add("onClick", "if (!confirm('Are you sure you want to delete?')) return false;");

What am I doing wrong here?

Thanks.
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message news:e1**************@TK2MSFTNGP11.phx.gbl...

"Matt Berther" <mb******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Mike,
I have scoured the web looking for an example of how to do a
javascript confirm box in .NET.


control.Attributes.Add("onClick", "return confirm('Your Message');");

where control is the control you want the confirm box attached to. Keep in mind that this will not postback unless the user

selects OK.

--
Matt Berther
http://www.mattberther.com

For a regular button this will work, for a linkbutton you will need

control.Attributes.Add("onClick", "if (!confirm('Your Message')) return false;");

because asp.net will add it's own onclick handler after this, to get the postback
to work. That's why you *need* the closing ";" here.

Hans Kesting

Nov 18 '05 #9
Sorry, I was doing this out of scope. Got it working now and it is great. THANKS!

Mike

"Mike Malter" <mi********@nospam.com> wrote in message news:ee**************@TK2MSFTNGP09.phx.gbl...
Guys,

When I do this I get the following compiler error:

C:\Projects\SSSC\Cheese\wwwroot\ManageBrand.aspx.c s(51): Invalid token '(' in class, struct, or interface member declaration

My code is as follows:
protected System.Web.UI.WebControls.Button bDelete;
bDelete.Attributes.Add("onClick", "if (!confirm('Are you sure you want to delete?')) return false;");

What am I doing wrong here?

Thanks.
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message news:e1**************@TK2MSFTNGP11.phx.gbl...

"Matt Berther" <mb******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Mike,

> I have scoured the web looking for an example of how to do a
> javascript confirm box in .NET.

control.Attributes.Add("onClick", "return confirm('Your Message');");

where control is the control you want the confirm box attached to. Keep in mind that this will not postback unless the user

selects OK.

--
Matt Berther
http://www.mattberther.com

For a regular button this will work, for a linkbutton you will need

control.Attributes.Add("onClick", "if (!confirm('Your Message')) return false;");

because asp.net will add it's own onclick handler after this, to get the postback
to work. That's why you *need* the closing ";" here.

Hans Kesting


Nov 18 '05 #10
Hello Mike,
C:\Projects\SSSC\Cheese\wwwroot\ManageBrand.aspx.c s(51): Invalid token
'(' in class, struct, or interface member declaration

My code is as follows:

protected System.Web.UI.WebControls.Button bDelete;

bDelete.Attributes.Add("onClick", "if (!confirm('Are you sure you want
to delete?')) return false;");


My guess is that this has something to do with the sorrounding code, as this block looks fine. Could you post the rest of the method?

As a side note,
if (!confirm('Are you sure you want to delete?')) return false;
is actually the same as
return confirm('Are you sure you want to delete?');

and possibly much clearer to read.

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #11

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

Similar topics

5
8949
by: Logger | last post by:
Help, I’m trying to implement a confirm button on an asp.net page. I have it attached to a asp:button control. In the button1 click event I call the CreateConfirmBox subroutine. The Box comes...
0
1554
by: Joe Finsterwald | last post by:
Recently I needed to add a confirm to a LinkButton that called a JavaScript function on success, and did nothing on failure. I found documentation on adding a confirm, but not on how to place a...
13
5619
by: Chris | last post by:
I can create Javascript confirm message boxes during page creation, etc adding them to the button attributes (many good posts on this!). But how can I add this event after the button is pressed? I...
1
3809
by: freshRecruit | last post by:
Hi, I am having a problem, and is driving me nuts and my deadline is fast approaching. Please do help me.. This is a webapplication with a usercontrol which has some buttons for adding,...
1
2443
by: chris | last post by:
Hi, In ASP.NET page, when my user tries to edit a record in gridview, I need to display a confirmation message, if another user is editing the same record. Since the confirmation message will...
4
10010
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit"...
8
4005
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form...
5
5397
by: strikefiend | last post by:
Ok, I'm somewhat new to .NET C# language and am having a bit of trouble. I'm trying to run the javascript confirm() method from my ascx page but I'm currently using C# as the main language of the...
4
7480
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
4
8622
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel?...
0
6904
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
7037
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
7080
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...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.