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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |