Capturing the response from a confirm message box

I created a confirm message box using:

private void MessageBox2(string msg)

{

Label lbl2 = new Label();lbl2.Text = "<script language='javascript'>" + Environment.NewLine + "window.confirm('" + msg + "')</script>";

Page.Controls.Add(lbl2);

}

and then call it later with:

MessageBox2("Testing Confirm Function");

 

The problem is, I have no way of determining what the client has selected Ok or Cancel. I need to be able to test that click inorder to determine if the record to the database will be updated. Any suggestions?

0
VB_Gone
7/3/2008 9:15:03 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

7 Replies
1229 Views

Similar Articles

[PageSpeed] 8

 Find the answer in this post http://forums.asp.net/t/1199047.aspx


Hosam Kamel

Remember to click on Mark as answer on the post that helped you
0
HosamKamel
7/3/2008 9:34:23 PM

You need to capture the boolean return value of window.confirm and check it for True (ok) or False (cancel).  Since this happens client side I think you need to stuff the value into a hidden field and return it to the server when the form submits.

0
kraznodar
7/3/2008 9:37:53 PM

 hi,

1. Have a hidden field (comes with stanard ToolBox in ASP.NET)

2. Make your Javascript routine populate that field - you will have to write a little more elaborate function than a one-liner you have there
     function confirmIt(msg)
     {

          if(confirm(msg))
          {
             document.getElementById("hiddenFieldID").value = false;

          }
         else...... and so on.....
3. Call your function
4. On page load on your server-side have a call that will evaluate the value of your hidden field. Make sure that you don't forget to inclose (if needed) this call witin this.IsPostBack and reset the hidden field

C'est tout. 

 

 

         


Alexei Fimine
_____________
Don't forget to mark this post as "Answer" if it indeed answered.
0
fimine
7/3/2008 9:39:44 PM

 If you just want to get the confirm result on the client side so that it used to decide to submit the form or not , then you can follow the link mentioned by hosam,

But if you want to use the Confirm result on the server side , you can refer to this example :

 

  protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
MessageBox2(" What do ou think ? ");
}
private void MessageBox2(string msg)
{
string script = string.Format(" var HiddenField =document.getElementById('{0}'); HiddenField.value = confirm('{1}');", HiddenField1.ClientID, msg);
ClientScript.RegisterStartupScript(this.GetType(), "confirmscript", script, true);
}


protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(" Result " + HiddenField1.Value);
}

  

ASPX:

 

            <asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="show result" /></div>
  
Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
7/3/2008 9:47:00 PM

anas:

 If you just want to get the confirm result on the client side so that it used to decide to submit the form or not , then you can follow the link mentioned by hosam,

But if you want to use the Confirm result on the server side , you can refer to this example :

 

  protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
MessageBox2(" What do ou think ? ");
}
private void MessageBox2(string msg)
{
string script = string.Format(" var HiddenField =document.getElementById('{0}'); HiddenField.value = confirm('{1}');", HiddenField1.ClientID, msg);
ClientScript.RegisterStartupScript(this.GetType(), "confirmscript", script, true);
}


protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(" Result " + HiddenField1.Value);
}

  

ASPX:

 

            <asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="show result" /></div>

  

 

Sorry but I am looking for the windows.confirm box to show up not a button

0
VB_Gone
7/4/2008 3:51:56 PM

Let me reword my post, What I need is a window.confirm message box to appear on the screen, from which I want to be able to test against response inorder to add a new record or do nothing to the database. I DO NOT want to recreate the wheel with some custom built box, I want to use the built in windows message box for this.

0
VB_Gone
7/4/2008 3:57:01 PM

Ok , you can register the confirm script for the Add button , like this

 

<asp:LinkButton ID="lnkAdd" Text="Add" runat="server" 
OnClientClick=" return confirm(' are you sure you want to add this item ? ') ; ">
</asp:LinkButton>
 
Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
7/4/2008 5:22:58 PM
Reply:

Similar Artilces:

How do you get the response from message box?
Hello, I have a confirm message box that displays "yes" or "no", If a user clicks "yes", do something, but for some reasons I can't get the message response from the message box in the code behind.  Can anyone shows me how to get the response from the message box?  Thanks  Here is the code that display the confirm message box: btnClick.Attributes.Add("onclick", "return confirm('Are you sure you proceed?');");  You can use below. If yes is clicked it will go further.btnClick.Attributes.Add("onclic...

How to get the response from this javascript confirm message
How to get the response value ie true or false when click the yes in confirm box. ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "return confirm('Do you want to continue');", false);  note: Not using "attribute.add" because if use this once javascript is bind to the browser it will show the confirm box when not choose the check box for delete.  please give me the solution as soon as possible confirm returns a true if clicked is yes and false if no.. put an if statement to it.. if(confirm()) { clicked yes ...

Cancel response from confirm message box is not working.
Hello, I have this ScriptManager class below for the confirm message box along with the function calls from the server side for the "Ok" response.  If the response is Ok from the confirm message box, it will goes on in the code and call one of the function from the server side "PerformSearch()" and if the response is Cancel, don't do anything and close out the confirm message box.  When I click the "Cancel" button on the confirm box, it still goes on and perform a function from the server side  just like the "Ok" respons...

How to get the return value from confirm message box?
In this case, I have a radiobuttonlist control, if the user changed the radiobuttonlist's index, then the application will be prompted a confirm message box. If use click the "OK", then proceed, otherwise, remain unchanged. I tried to write the code under the event (radiobuttonlist_SelectedIndexChanged): radiobuttonlist_SelectedIndexChanged (Byval sender as object, Byval e as Eventargs) response.write("<script lang=javascript>confirm('Confirm to proceed!')</script>") textbox1.visible = True However, no matter what the user chosen, the t...

Problem dealing with the confirm message box in C#.net
Hi..i am actually trying to do something like this.When a user select a particular option from a dropdown list and click a 'Go' button, a confirm message box will be displayed if the user has selected that particular option.Other options selected will not display that confirm box when the 'Go' button is clicked.Once the user press the ok button on the confirm box,it will proceed to perform other tasks.How do i do that?..I try using the following code but it doesnt really work..the confirm box will always popup everytime the 'Go' button is clicked except for the first time u clicked on it. ...

Capture return value of javascript confirm message in VB.NET
Capture return value of javascript confirm message in VB.NET I was trying to use javascript to capture return value of confirm message box at codebehind using hidden HTML input box. function getMessage() { var ans; ans=window.confirm('Is it your confirmation.....?'); if (ans==true) { document.Form1.hdnbox.value='Yes'; document.Form1.textbox1.value = 'test'; } else { document.Form1.hdnbox.value='No';} } To retrieve the value in .aspx form I am using following code on button click Private Sub Button4_Click(ByVal sender As System.O...

How to get return from confirm message box when text change event
 hi all,i need to use confim message box to get response when the text change event.and i need to use that response in code behind.please send me answer qiuck.thanks See the example in this link : http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.interaction.msgbox(VS.80).aspx   You can do something like this  Dim msg As String Dim title As String Dim style As MsgBoxStyle Dim response As MsgBoxResult msg = "Do you want to continue?" ' Define message. style = MsgBoxStyle.DefaultButton2 Or _ MsgBoxStyle.Critical Or MsgBoxStyle.YesNo ...

confirm message box with yes/no, plus other controls value in the message
I have 2 issues: --I need to show a confirmation message box with yes/no, but it only shows OK and Cancel.  See code below. Is it possible to show yes/no? and if so, how? --The other issue is I need to show the message with the value of other control in the message, but can the code below works with other controls named inside of the message? and if so, how? For example:  the message would show something like:  are you sure you want to update and override [dropdownlist.selectedvalue here] and [textbox.text here]? any idea/help would be really appreciated. I'm ...

How to get Soap messages for web service(Request response xml message)
Hi all, i am using web service in my windows application, is it possible to get the xml message which will be sent to web service and same for response. Please let me know if its possible or not.   Thanks Hi, Use Soap Extensions to log the outgoing and incoming XML. You must add the SoapExtension attribute to the proxy class of the Web Service. The proxy class in VS.NET is located in the Reference.cs in the web references folder. http://msdn.microsoft.com/en-us/library/esw638yk(VS.71).aspx Hope this helps.Microsoft Certified Professional Developer - Web Developer Hi Pr...

Confirmation message box
I would like to have link "delete" below each address on the form (repeater control). However when user clicks I would like to open message box "Are you sure... ?" with Yes, and No buttons.  It used to be simple in VB, msgbox... How do I do it in ASP.NET? Do I need to inject java script? How?Rafal Zikbay.com - Free Classifieds (Search Over 5 mln jobs on Zikbay.com) DNN Direct add a javascript like so in your header  function ConfirmDelete()        {            return confirm('Are you sure?...

confirm Message box
 hi all,i need to use confirm message box and i want to get response from this confirm message box,when if click yes button i need to code it and also no button.my problem is how i get this response into my  C# class for assign to any variables.im use ajax 1.0  and Visual studio 2005 for devolop my web form.thnks     harshalasith:i want to get response from this confirm message box,when if click yes button i need to code it and also no buttonCan you tell me how do you want to use the response from confirm message box? In most common way, a confirm message box...

Message box response
I want to use the following message box which will pop up when a user clicks a button. The options the user has are "OK" or "Cancel" How do I program an If statement to take account of the users response E.g. If the user clicks Ok do something, if they click Cancel, do something else. btnGoDelete.Attributes.Add("onclick", "return confirm('Are you Sure you want to delete this User Account?');") Also is there a way to change the Ok/Cancel to something else e.g Yes/No? I don't believe so.Brian"Trust in the Lord and do what...

Response to Message box
I want to use the following message box which will pop up when a user clicks a button. The options the user has are "OK" or "Cancel" How do I program an If statement to take account of the users response E.g. If the user clicks Ok do something, if they click Cancel, do something else. btnGoDelete.Attributes.Add("onclick", "return confirm('Are you Sure you want to delete this User Account?');") btnGoDelete.Attributes.Add("onclick", "if (confirm('Are you Sure you want to delete this User Account?') { DoSomet...

Message Box Confirmation
Hi My form contains a datagrid of list of students and check box next to each studentname: Check        StudentName And in the buttom of page I have a save button. after clicking save the system will check each student if check or not to display confirmation message says: an email will be sent to the following students: List of checked Students Are you sure you want to save and send? If yes information will be saved and an email will be sent, otherwise nothing will be changed. The question is how to add my confirmation message in the postback ...

Web resources about - Capturing the response from a confirm message box - asp.net.getting-started

Capturing the Friedmans - Wikipedia, the free encyclopedia
Jarecki initially was going to make a film about children's birthday party entertainers in New York, including the popular clown David Friedman. ...

Newscasts on Facebook Are Capturing Attention
With Facebook becoming more and more of a source of news , manager of strategic partnerships for broadcast Beth Loyd examined the newscasts being ...

Capturing Growth: Photo Apps and Open Graph
People upload an average of more than 300 million images to Facebook every day, making photos a core part of the Facebook experience. Developers ...

Sight - Save Articles, News and Recipes to Read Offline and Share Content by Capturing a Screenshot
Get Sight - Save Articles, News and Recipes to Read Offline and Share Content by Capturing a Screenshot on the App Store. See screenshots and ...

Capturing the KC-135 on video - Flickr - Photo Sharing!
U.S. Navy Mass Communication Specialist 2nd Class Scott Taylor, assigned to Fleet Combat Camera Group Pacific Detachment, takes video footage ...

Camera Extras for Nokia Lumia More Options for Capturing Great Pictures - YouTube
Camera Extras for Nokia Lumia More Options for Capturing Great Pictures - YouTube

Capturing the baby boomer market
Cashed-up boomers are a demographic businesses can no longer ignore.

Capturing an Australia in transition
Rennie Ellis was a visionary in an emerging arts culture.

Capturing Kurt Cobain
Melbourne-based Stephen Sweet, who photographed Nirvana for the now defunct British magazine Melody Maker and is presenting a Cobain retrospective ...

A year capturing the trauma and love felt by the families
I started photographing families from migrant communities in western Sydney with Alzheimer's disease because I didn't see a lot of representation ...

Resources last updated: 1/16/2016 8:41:35 AM