How to access yes/no value from a popup window in the code-behind C#?

I've have looked into plenty of threads about this but nothings working for me. Basically I want to ask the user to confirm, if the user says yes then execute some c# code in the code-behind otherwise if the user says no then do nothing and let the user be able to click the button again.

 

Here's some stuff I've tried:

 In the aspx file,

                <script language="javascript" type="text/javascript">
                     function getMessage()
                     {
                     var ans;
                     ans=window.confirm('Is it your confirmation.....?');
                     //alert (ans);                     
                     if (ans==true)
                      {
                        //alert('Yes');
                        document.confirm_page.hdnbox.value='Yes';
                       }
                     else
                     {
                        //alert('No');
                        document.confirm_page.hdnbox.value='No';
                     }
                </script>

 In code-behind c# file,

 
in pageload, Button1.Attributes.Add("onclick", "getMessage()");

a seperate buttons click event,  Response.Write(Request.Form("hdnbox")); 


The above doesn't work. It doesn't even show the yes/no box when I leave the document.confirm_page.hdnbox.value = 'no' line in, if its taken out though it shows the yes/no box but doesn't do anything then.

 Thanks
 


Using Visual Studio 2005. Language: C#
-1
finittz
1/29/2008 6:16:33 PM
asp.net.client-side 24353 articles. 1 followers. Follow

5 Replies
2291 Views

Similar Articles

[PageSpeed] 59

Don't make it harder than it needs to be.  First of all, you can't access the Javascript confirm value in code-behind.  That's not how it works.  You can use Javascript to cancel the event when the user clicks "Cancel", and therefore your server-side won't even be called.  That's how it works.  Example...

    Button1.Attributes.Add("onclick", "if(!confirm('Are you sure?')) return false;")


Yes, only one line.  You need nothing else.  The Button1_Click server-side subroutine will not get fired unless they click OK.

Best regards...


Josh Stodola ← Come check out my blog!
-1
JoshStodola
1/29/2008 6:28:46 PM

In order to continue executing button click you have to return true from somewhere in your function.

                     if (ans==true)
                      {
                         //alert('Yes');
                         document.confirm_page.hdnbox.value='Yes';
                         return true;
                       }


__
Please mark post as answer if it helps, if not come back and ask again!
1
millet
1/29/2008 6:35:00 PM

millet:
In order to continue executing button click you have to return true from somewhere in your function.

That's not exactly true.  It's best to only return false when you know you have to.


Josh Stodola ← Come check out my blog!
1
JoshStodola
1/29/2008 7:36:07 PM

Thanks, I used that code as well as having the buttons original click event. So if they pressed ok then it would execute the original click event, otherwise if it was false it would do nothing and not execute the original click event. Thanks.  


Using Visual Studio 2005. Language: C#
1
finittz
1/29/2008 7:39:53 PM

You're welcome.  Glad you got the problem solved!


Josh Stodola ← Come check out my blog!
-1
JoshStodola
1/29/2008 7:41:23 PM
Reply:

Similar Artilces:

Atlas client side control value available to server side C# code behind
I have an existing ASP.NET application. The page contains a datagrid (asp:datagrid). In my current C# code behind, I fetch data from SQL Server 2005 and bind to the datagrid when a button is selected (Click event). There can be many entires in the grid however, so the user typically enters text in a textbox as a filter on the returned results from SQL Server 2005. Now after studying an Atlas sample animalservice http://atlas.asp.net/docs/atlas/doc/data/default.aspx, with an HTML suggestion text box, I would like to use client-side Atlas to give the user a better indication of...

How to open a popup window from C# code behind
Hi, When users click on submit button on my application, first it validates the data using requiredfieldvalidators, and then once all the data is perfect a popup window should open that tells them "please wait, processing request", the window stays as long as the parent unloads, I am able to do it by using Javascript and adding OnClick attribute to the button, but the problem is the popup opens everytime we click the button, even if it it fires the validators and not move to the next page, Can Anyone Help?? How about adding the popup code to the onsubmit event handler of the form tag inst...

How to open a popup window from C# code behind
Hi, When users click on submit button on my application, first it validates the data using requiredfieldvalidators, and then once all the data is perfect a popup window should open that tells them "please wait, processing request", the window stays as long as the parent unloads, I am able to do it by using Javascript and adding OnClick attribute to the button, but the problem is the popup opens everytime we click the button, even if it it fires the validators and not move to the next page, Can Anyone Help?? How about adding the popup code to the onsubmit event handler of the form tag inst...

Accessing a client side TextArea from Code Behind
I've got a standard HTML text area on a .aspx page: <textarea name="EditorValue" id="EditorValue" style="DISPLAY: none"> I need to reference the text contained in this textarea within the pages code behind file, something like: Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click Response.Write(***THE TEXT WITHIN THE EDITORVALUE TEXTAREA***) End Sub Unfortunately, i cannot use the runat=Server attribute with this particular textarea (for various reasons). Is there any other way of g...

getting client side value in code behind
Dear all, i have declared a variable in client side to hold a particular value..i have to access this variable within pageload evrnt.how can i do it???please suggest   mama Hello, You can make use of Hidden variable, which can be accessed in client side as well as in code behind. I hope this will be helpful..S.SRIRAM hello take a hidden field in your page fill it with ur javascript variable then access the value of hidden field in page loadHAPPY CODINGhttp://shobhitrai.blogspot.com/ Hi It is an easy codding man.. just add runat="server" attribu...

open a popup window from.net code behind
Hi I am trying to open a new window from a button in my aspx side. This works, but I have to push the button 2 times before it open. Any idea? Public Shared Sub OpenPopUp(ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String) Dim clientScript As String 'Building the client script- window.open clientScript = "window.open('" & PagePath & "')" 'register the script to the clientside click event of the opener control opener.Attributes.Add("onClick", clientScript) End Sub Sub Button1_Click(sender As...

Accessing client side controls from code behind
I need to access client side controls <input type=text id=t1 name=t1> from server side code. I understand that we could access it using Request.form() or request.params() but when the page is sent back to the client after postback I want to assign a different value to this text box. Is this possible or do I have to convert this text box to server side control by putting runat=server. Second this is what is clientID property used for ? can I use it in this scenario. Please help, Buddythanks,Buddy to access a control in code behind you must add two attributes 1) the id 2) runat=...

how to open popup window through javascript in code behind( popup window should be aligned center)
I want to use javascript in code behind to open popup window. I have Datalist inside which there is linkbutton. On click of linkbutton open popup window through javascript & that pop up window should be aligned centraly.Regards,Mahesh--------------------click "Mark as Answer" on the post that helps you. Friend, Try this sample . <html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title>        <style>    .blue{ bac...

C# code behind variable in client side javascript
Is there a way to add a code behind variable to a javascript: window.open command in the NavigateURL or DataNavigateUrlFormatString of Hyperlink Columns and Bound Hyberlink columns? M view post 1039Sushila Bowalekar PatelVisual ASP/ASP.NET MVPhttp://weblogs.asp.net/sushilasb How about inside a plain client side window.open call in javascript? view post 1034Sushila Bowalekar PatelVisual ASP/ASP.NET MVPhttp://weblogs.asp.net/sushilasb Thanks a ton! ...

get html textbox value in C#.net(code behind)
  i am new to ASP.net. Can anybody say how to get Input textbox value in C#.net. b4 sending answer Thankx  string value = Resquest.Form["textboxname"].ToString(); Hi,There are two ways to access it. 1) Make it runat="server" and access it in code behind like textbox1.value2) Another way is by using     Request.Form["textbox1"].ToString(); I hope this will be helpful to you.Thanks, Alpesh DhaneshaPlease don't forget to "Mask as Answer" if it helped. just add runat =server to html  ...

Open popup window on click of button event from code behind side
 Hi friends I have one button called Preview which is placed in upadate panel. Now I want to open popup window on click of that button. I can call javascript onclientclick event but before open popup window i want to get some values from current window.I dont want to pass that value in query string. Here is my code <pre> ClientScript.RegisterStartupScript(this.GetType(), "JS", "javascript:window.open('PreviewPop.aspx?DesignID=" + txtImageHide.Value + "','MyTitle','height=250,width=505, top=100, left=100, scrollbars=yes, res...

Access client-sde set cookies from server-side code behind
Hi there,I found another post relating to this topic but no one gave any example code, everyone just said: "yes, you can access cookies that you set client side (using javascript) from the code-behind, server side".My situation is this:I have an external web application making a call to one of the pages in my application . It passes a variable via the query string.This external site is requested a restricted resource and thus users must sign in before continuing.So that it makes a little more sense, I have coded the requested page to recognise calls from the external application (t...

Question about client side and code behind code
How is code behind code processed on client side? I ask because I'm trying to figure out a problem I have with a link button in a gridview. If I open the page and run it as normal everything fires fine. I click on the link button and it loads the new page. However if I email the page to myself and click on the link button nothing happens. I do not think that the Gridview_Rowcommand fires. The link button represents a DB ID field and all the code is in the GridView_RowCommand event in the code behind and fires a Server.Transfer at the end to load the new page. I have tried Response.Redi...

how to get value from client side script Prompt window to a session var in .net
hi guyz, i hav a problem with getting a value from a client-side inputbox to a session var in .net. is this possible? however, when i click submit button this is the code that's triggered. dim sb as New System.Text.StringBuilder sb.append("<script language=" & """" & "vbscript" & """" & ">") sb.append(vbcrlf) sb.append(vbcrlf) sb.append("do while xLate =" & """" & """") sb.append(vbcrlf) '//prompt window, val...

Javascript confirm message in c# code behind,by clicking ok popup window open
how can i set a confirm javascript message in c# code behind and by clicking ok i have to open a pop up .aspx page. Hello,     Add onclick attribute with javascript function containing window.open() within your c# code. btn.Attributes.Add("onclick", "javascript:window.open('YourPage.aspx')")  Thanks,santosh_maharajaPlease mark as answer if you got expected solution. http://plugins.jquery.com/project/confirm  Cool stuff // The action. $('span').mouseover(function() { $(this).html('Here is the offer'); });   $(&...

Field1 value --> variable name ; Field2 value --> variable value (C# code behind)
 I would like to add quantities to variables based on two fields in a table.  The table includes two field names: ingredient, weight.  Assume a simple formulation: add 50 lbs water, add 20 lbs eggs, add 10 lbs water, add 5 lbs salt.The table would have: water, 50 eggs, 20 water, 10 salt, 5The variables water, eggs, water and salt have already been defined. I want something that will cycle through and add the quantities (lbs) to the variable. Ingredients can appear more than once in a formulation--notice that water appears twice and at the e...

How to get the Client side values in server side code.
Hi all, i have a proble i need to get the client side javascript values in C# code at server side. how can i pass those values? i am using version 1.1, i kno thatwe can use callback events mechnisam in 2.0 or ajax ,apart from that how we can pass? My problem is i need to stop the execution of the code based on after reciving values from the client   any ideas please???   Million thanks RamCheersRam MCP Hello Ram, a common approach is from javascript set an hidden field, then issue a postback. On the server-side, handle the post-back. Feel free to go deeper in your que...

I'm having a problem with creating dynamic control (dropdown) on client side & accessing that control on code behind.
Hi Team, In page load default I’m showing "start time" dropdown,” End time" dropdown. I'm giving one checkbox option to user, if user checks I’m enabling the button. On that button click, I want to create client side dynamic controls for adding on start time, end time. Start Time with 3 dropdown Hours, Mint, Unit (AM, PM). End Time with 3 dropdown Hours, Mint, Unit (AM, PM). This scenario is for measuring "SAMPLE “multiple start time, end time. I want to calculate the duration of start, end time & show to user. Can any one give me the idea or ...

Accessing Client side variable from server side code?
Hi,  I am trying to use vbscript to run a process on the client machine. Once that process finishes I want to use the resulting value in my server side code behind file. Does anyone know a way to do this? I know that I can set server side session objects to a client variable by doing something like this: <script language="vbscript" type="text/vbscript">  strSubject = <%=Session.Item("Subject") %> </script>  but I have no idea how to do that in reverse. Thanks!    Filed under: too much coffee.  LOL! ...

Client side code accessing server side variables
I am attempting to send a variable value from C# to the page for Javascript to access and use.  Basically I am using a prompt window in my server side javascript to capture a value and update the database with it.  If the value entered is not unique (because this is a unique identifier) I return a value indicating this.  I want this value available to my javascript code so I can provide an alert message telling the user to try again with a unique value.  If there is a way to make the message come right from my C# code behind page that will work for me too. Thanks ...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

Client side code to pass values to server side variable?
Hi there, I have ListBox_SelectedTextChanged() method that creates another list box in the runtime as follows: // Get Action Level List lbxActionLevel = new ListBox();lbxActionLevel.ID = "ddlA" + i.ToString(); lbxActionLevel.Width = 100; lbxActionLevel.Rows = 2;SqlDataReader dr = new BusinessLogicLayer().bllGetActionLevels(); lbxActionLevel.Items.Clear();while (dr.Read()) {ListItem lAction = new ListItem(); lAction.Text = dr.GetString(1).Trim();lAction.Value = Convert.ToString(dr.GetInt32(0)); lbxActionLevel.Items.Add(lAction); lbxActionLevel.SelectedIndex = 0; } I ...

How to read cookies value on client side from server side code?
 I read an article which explains on how to read the client side cookies from C# code by doing something like://Grab the cookie 9: HttpCookie cookie = Request.Cookies[strCookieName];I am very confused here. Server side code in on the server side, so how can a server side code read the cookies on the client machine?I thought that only a client side script like Java Script  can read the client side cookies.Kindly explain...please.thanks.   Each time you request a page on a domain, the browser looks for a cookie for that domain on the client machine if it exists then it ...

How to take value from client side control from server side code?
Hi all, I would like to know that, how to access client side control in server side code? Here is an example.. I am having the textBox in client side like <input type="text" id="textBoxUsername" name="textBoxUsername"/> I need to take the value from this textBox in button click event which is server side code. private void buttonShow(object sender, System.EventArgs e) { //I need to access this textBox here. } How to do that? Thanks R. eswaran. hi you need to make it run at server. <input type="text" id="textBoxUsername"...

Web resources about - How to access yes/no value from a popup window in the code-behind C#? - asp.net.client-side

Looking at the code behind our three uses of Apache Hadoop - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Looking at the code behind our three uses of Apache Hadoop geschrieben. Du kannst den vollständigen ...

How Heartbleed Works: The Code Behind the Internet's Security Nightmare
By now you've surely heard of Heartbleed, the hole in the internet's security that exposed countless encrypted transactions to any attacker who ...

Anatomy of an interactive: a look at the code behind our Second Screen
... and Paralympics coming to town, this presented the perfect opportunity to try it on. Being mainly responsible for the client-side code, I'll ...

How Heartbleed Works: The Code Behind the Internet's Security Nightmare
By now you've surely heard of Heartbleed, the hole in the internet's security that exposed countless encrypted transactions to any attacker who ...

Resources last updated: 2/14/2016 4:34:34 PM