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 += "\n<script language=\"JavaScript\" type=\"text/javascript\">\n";

javaScript += "<!--\n";

javaScript += "confirm('" + confirmedMsg + "')";

javaScript += "// -->\n";

javaScript += "</script>\n";

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. 0 followers. Follow

6 Replies
1005 Views

Similar Articles

[PageSpeed] 10

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 += "\n<script language=\"JavaScript\" type=\"text/javascript\">\n";

javaScript += "<!--\n";

javaScript += "confirm('" + confirmedMsg + "')";

javaScript += "// -->\n";

javaScript += "</script>\n";

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 = @"<script language='JavaScript' type='text/javascript'>
            confirm('" + confirmedMsg + @"');
        </script>"

this.RegisterStartupScript("AlertScript", javaScript);

 

u go for this code


We Are Looking for .NET/PHP Projects

Contact Details :-

 Email - sameer.khanjit@gmail.com

 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 += "\n<script language=\"JavaScript\" type=\"text/javascript\">\n";

javaScript += "<!--\n";

javaScript += "confirm('" + confirmedMsg + "')";

javaScript += "// -->\n";

javaScript += "</script>\n";

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
Reply:

Similar Artilces:

adding an ok/cancel confirmation box
Hi,    I am trying to add the ok/cancel confirmation box in my application. The user will search for some records, and if the number of rows returned from the search result is greater than 100, then a confirmation box will be displayed saying that “there are large number of records, do you want to continue”.   I do not know the best way to do this. Can you please help me on this?  I researched on Google, and it said to add a msgbox in the toolbox. But I can’t see that in my toolbox. I also tried adding that, but didn’t find one.  Thanks, Ashu   Ther...

Confirm Message Box with OK or Cancel option in C#
Hi  All, I have a function call which  results in two conditions(True and False).When the condition is false,I wanted the code to display a message box with the two options (OK and Cancel) and when the user clicks the OK button It should direct to another page. Please anyone help me with the code ( in C# ) to display a confirm message box with this two options.Its urgent. Thanks for your help.     private void button3_Click(object sender, System.EventArgs e) { if (MessageBox.Show("Really delete?","Confirm delete", MessageBoxButto...

Perform JavaScript Client Side Confirmation from a VB.NET DataGrid
Hi, I when I delete an item from the database through a Datagrid I want to get a messagebox popingup to give me the choise to Confirm it...in case I clicked the wrong item....the way it works now it just deletes it....can any one help me with an Example I have no Idea how to do this...I found an article in C# but it didnt help me at all. here is my source code <asp:DataGrid ID="dgCustList" Runat="server" AutoGenerateColumns="False" DataKeyField="id" AlternatingItemStyle-BackColor="#F6F6F6" HeaderStyle-BackColor="#C4B58E" CellSpacing="0" CellPadding="2" GridLines="Vertical" Width="100%"...

Modal Popup on Client-Side
Hello, Is it possible to determine in the client API that a user clicked the OK/Cancel option, either via enumeration or boolean property?  I'm accessing this on the client only, and am trying to figure out how I can tap into this to perform a client action. Thanks.Brian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4). You can do it by handling the following properties... OnOkScript - Script to run when the modal popup is dismissed with the OkControlID...

How to display a client-side confirm dialog box if the user clicks on the first row in my datagrid
I could n implement that, this what I tried: I define my datagrid with :  <ItemTemplate> <a id="MenuItem".......><%#container............>  pls check my aspx html code bellow. Thn, In the ItemDataBound event handler of my datagrid, I test if e.Item.ItemIndex=0, if so, I create an object of type control and assign it to e.item.controls(0) , then I try to add the client side property: atributes(....) to that control. The pb is: the control object that I create doesn t take the client property :  attributes(“onclick”)=…. My question is:  What type are...

how to call a c# function if user click on ok button of java script confirm box in .net
hi, i have one problem that is i'm adding the new user to database, if that user is already exist in the database one pop up should display with message like 'user already exists are u sure you want to update the role of the user' with 'yes' and 'no ' buttons on pop up, if user click on 'yes' button then it should call edituser() method of c3.net other wise it should reset the selected controls. how to do this using extenal .js file with javascript confirm box   Hi When user click on "Yes" set a asp.net hidden field value to be "t...

System.ArgumentException: Invalid postback or callback argument
I can't figure out why I get this error.  Yes, the error description should tell me but I don't understand it or how to resolve my situation so bare with me.First let me explain the code I have going on.In my PageLoad I have registered this script to the page:  Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "DeleteConfirmation", "function confirmDelete(){if(confirm('Are you sure you want to Delete?')){return true;}else {return false;}}", True)Then, in my DataGrid, I have wired up each ImageButton (that's wrapped in an ...

System.ArgumentException: Invalid postback or callback argument
I can't figure out why I get this error.  Yes, the error description should tell me but I don't understand it or how to resolve my situation so bare with me.First let me explain the code I have going on. In my PageLoad I have registered this script to the page:  Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "DeleteConfirmation", "function confirmDelete(){if(confirm('Are you sure you want to Delete?')){return true;}else {return false;}}", True) Then, in my DataGrid, I have wired up each ImageButton (that's wrapped in...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

communication between client side(java script) and server side in .net project
I have a question which is, when building a .net project, we are able to use server side code and client side code(java script). How do they communicate? Thanks Client Side coding works with the WebBrowser. So when ever you write client side code you have to keep browser compatability in your mind and you have to code. Server Side code works with Web Server (IIS) and it's ASPNET ISAPI's. The won't directly communicate with each other. But using AJAX you can all server side code from Client Side! Example article on Ajax@ http://www.devarticles.com/index2.php?option=content&task=...

can clear server side text box value from client side.?
Hi, function Disab() {    if(document.all.chkSPTariff.checked)     {        document.all.txtVFX.disabled=false document.all.txtVHSFO.disabled=false    }  else  {     document.all.txtVFX.disabled=true document.all.txtVFX.value=""               }   This is how i am clearing  the  text for <asp:TextBox>. Ofter i submit, i wonder to see the old value from serverside , like txtTemp.Text is h...

confirm ,ok, cancel
hi I am using 2 buttons named edit and update. in asp.net and c#. There is one textbox control named "txtSelectionsNew". there is 1 datagrid.,it is having bound column edit i.e push button. when i click edit button in datagrid,the corresponding fields will display into textfiled named txtselectionsnew. at that time i am making readonly for this text control true. after clicking on edit,i'll change that textbox control and i'll do update by clicking on update.for updation i wrote one function. when i click on update button,confirm box will show ok,cancel. for this i wrote javascript c...

Web resources about - How to return OK or Cancel in the confirm box - asp.net.client-side

Facebook Confirms Streamlined Post Scheduling, Announces Easier Photo Uploading For Page Admins
Facebook officially announced the improvements to the post-scheduling process that began leaking out last week, as well as an easier way for ...

4th XMRV Study Fails to Confirm Association with CFS - Facebook
The CFIDS Association of America hat eine Notiz mit dem Titel 4th XMRV Study Fails to Confirm Association with CFS geschrieben. Du kannst den ...

Slide Confirms Cuts to Ad Sales Staff, Continues to Shift Focus
Late last month, we reported that direct to consumer virtual goods sales were now accounting for at least half of Slide’s revenues, and that ...

Confirm Biosciences (@ConfirmBio) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Confirm Biosciences @ ConfirmBio ...

YouTube - Halle Berry talks The Call and confirms X-Men Days of Future Past
Veröffentlicht am 02.03.2013 Tinsel Talk: The Call Exclusive interview with Halle Berry. BlackTree TV's Jamaal Finkley talks to Halle Berry ...

Disney confirms that Star Wars: Episode 7 is filming in Abu Dhabi desert
Disney yesterday confirmed that the filming of Star Wars: Episode 7 is taking place in the desert in Abu Dhabi.

Team email confirms West Indies management knew of misbehaviour towards woman
An email from West Indies team manager Richie Richardson has emerged confirming team management was aware of misbehaviour from players towards ...

Analysis confirms coordinated hack attack caused Ukrainian power outage
... distribution power companies in Ukraine and to delay restoration efforts once electricity had been shut off, a newly published analysis confirms. ...

Tesla confirms: Model 3 will be unveiled in March
Since its release in 2012, the performance, ingenuity, safety, and commercial success of Tesla's Model S has far exceeded almost everyone's expectations. ...

John Chen confirms commitment to BlackBerry 10, updates coming in 2016
Following the recent reports that BlackBerry was all but abandoning BlackBerry 10, John Chen has cleared the air on the company's stance regarding ...

Resources last updated: 1/12/2016 5:35:41 PM