How to return OK or Cancel in the confirm box

Hi ,

I had implemented the confirm box by using Javascript in my asp code.

How can I check on the condition and perform future task?

My code is as follow:

confirmedMsg = "Confirmed Merging";

javaScript += " ";

this.RegisterStartupScript("AlertScript", javaScript);

 

I would like to have a condition :

If (ok)

{

// do something

} else

{

// do something

}

 

Please help.

Thanks

-1
bslim67
12/13/2007 6:18:42 AM
📁 asp.net.client-side
📃 24353 articles.
⭐ 2 followers.

💬 6 Replies
👁️‍🗨️ 2987 Views

From MSDN:

confirm Method


Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons.

Syntax

bConfirmed = window.confirm( [sMessage])

Parameters

sMessage Optional. String that specifies the message to display in the confirmation dialog box. If no value is provided, the dialog box does not contain a message.

Return Value

Boolean. Returns one of the following possible values:

true The user clicked the OK button.
false The user clicked Cancel button.

Remarks

The title bar of the confirmation dialog box cannot be changed.

Standards Information

There is no public standard that applies to this method.


[MCPD: WEB]
-1
Nail
12/13/2007 11:37:17 AM

Also where do you want to do some action in response of the confirmation? on client-side (by using javascript), or server-side (by using ASP.NET)?


[MCPD: WEB]
-1
Nail
12/13/2007 11:40:15 AM

Hi,

Just surround confirm("abc") with IF condition

like this,

if(confirm('Are you sure to delete this?')

{

    /// do some operation if Yes 

 else

{

    /// do some operation if No
 

 HTH.

Regards,

Mustakim Mansuri 

 


Regards,

Mustakim Mansuri (MCTS, MCPD)
Cybage Software Pvt. Ltd.
-1
mustakim
12/13/2007 11:42:36 AM

Hi ,

 I had try this but it did not work

 

confirmedMsg = "Confirmed Merging ";

javaScript += " ";

this.RegisterStartupScript("AlertScript", javaScript);

 

if (confirm("Are you confirmed"))

{

} else {

}

It give me an compilation error

"The name confirm does not exist in the current context"

Please help

 

1
bslim67
12/17/2007 2:13:29 AM

confirmedMsg = "Confirmed Merging ";
javaScript = @""

this.RegisterStartupScript("AlertScript", javaScript);

 

u go for this code


We Are Looking for .NET/PHP Projects

Contact Details :-

 Email - [email protected]

 Mobile no. : +91-9893795983

 View Blog

linkedin Asp.net Group

Don't forget to click €œMark as Answer€ on the post that helped you
1
sameer_khanjit
12/17/2007 4:46:18 AM

bslim67:

confirmedMsg = "Confirmed Merging ";

javaScript += " ";

this.RegisterStartupScript("AlertScript", javaScript);

 

if (confirm("Are you confirmed"))

{

} else {

}

It give me an compilation error

"The name confirm does not exist in the current context"

 

Hi bslim67,

You are attempting to invoke the client method €œconfirm€ on the server side. No doubt it will fail. If you want to €œdo something€ and €œdo something else€ on the client side, please refer to the following code:

        protected void Page_Load(object sender, EventArgs e)
        {
            ClientScriptManager cs = Page.ClientScript;
            string confirmedMsg = "Please choose a button";
            string cmd = string.Format("if(confirm('{0}')) alert('you clicked OK'); else alert('you clicked Cancel');",confirmedMsg);
            cs.RegisterStartupScript(this.GetType(), "StartUpConfirm", cmd, true);
        }

If you want to €œdo something€ and €œdo something else€ on the server side, please check my reply in the following thread.

Javascript confirm after server side validation
http://forums.asp.net/t/1171994.aspx


Sincerely,
Benson Yu
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
-1
Benson
12/18/2007 6:45:30 AM