need to use confirm boxes in a C# web page

Hi,
 I am trying to use a confirm box using Javascript in a web page for C#.
 What I need to do is to set a value of flag to 1(in the c# code) based on the result of the confirm box.
 This is my code

int flag=0;
string script2="<SCRIPT language='javascript'>"+
                     "var ans =confirm('Press ok or cancel');" + "</SCRIPT>";
            Page.RegisterStartupScript("confirm",script2);
  

 If the confirm box evaluates to true I want to set flag =1.
 How do I do it?

Thanks
satish   

-1
Satishr23
4/19/2006 12:06:50 AM
asp.net.getting-started 91979 articles. 2 followers. Follow

3 Replies
363 Views

Similar Articles

[PageSpeed] 32

your mixing client side javascript with server code, and this might take a little bit more work.

If you just want to hold the answer until your next postback, you can use a hidden field to hold the answer. Add this to your page:

<input type="hidden" id="myFlag" runat="server">

and modify your code as follows:

string script2="<SCRIPT language='javascript'>"+
                     "var ans =confirm('Press ok or cancel');" +
                       "document.getElementById('" + myFlag.ID + "').value = ans" +
                        + "</SCRIPT>";
            Page.RegisterStartupScript("confirm",script2);


then the next time your page posts, you will have the value:

string result = myFlag.Value;

If you want the page to postback immediately depending on the answer, that will take a bit more code.
1
sjmueller
4/19/2006 1:07:11 AM
Hi,
 Thanks .
Is there a way to do the coding in a C# page rather then the asp page.
thnks
satish

1
Satishr23
4/19/2006 1:51:15 AM

In the aspx file:
 <input type="hidden" id="Hidden1" name="Hidden1" runat="server">

That adds this to the CodeBehind:
 protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1;

Then add to the Page_Load event handler:

string scriptString = "<script language=JavaScript>\n";

// Store the confirm's return in the hidden control...
scriptString += "document.getElementById('" + Hidden1.ClientID + "').value = confirm('Overwrite?');\n";

// Do a new PostBack...
scriptString += GetPostBackEventReference(Hidden1, String.Empty) + ";\n";

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

RegisterStartupScript("ConfirmScript", scriptString);

if ( IsPostBack && Request["__EVENTTARGET"] == "Hidden1" )
{
     // Response.Write("Hidden1.Value: " + Hidden1.Value);

     if ( Hidden1.Value == "true" )
          // User answered OK
     else
          // User answered Cancel
}

Hidden1.Value = string.Empty;

NC...

 

1
NC01
4/19/2006 7:43:28 PM
Reply:

Similar Artilces:

How to get HTML Source of web page opened by web browser using vb.net
hello friends,         i have opened an web browser in vb.net using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim nullObject As System.Object = 0 Dim str As String = "" Dim nullObjStr As System.Object = str Windows.Forms.Cursor.Current = Cursors.WaitCursor Dim i As Int16 For i = 1 To 2 AxWebBrowser1.Navigate("http://www.google.co.in/search?hl=en&q=test&meta=", True) AxWebBrowser1.Document. Next Windows.Forms.Cursor.Current = Cursors.Default End Sub  ...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Fill in web page search box and get resulting web page via code?
Hi all, I have a web page: http://www.national.com/mpf/CO/COP8ACC5.html and I am wondering how I could simulate entering a value in the search text box, pressing search and then getting the resulting web page so I can process the information? I can process the info already if I manually get the source of the resulting web page, but not how to get the page automatically via programming. I have access to Delphi 5 and Delphi 2007 Win32 if this helps... Thanks in advance, Cheers, Paul. "The plastic veneer of civilization is easily melted in the heat of the mome...

How to get the source for a page using C/C++?
How to get the source for a webpage page using C/C++? Scenario: I'm in a JavaScript callback (for example the callHook callback) and I have a JSContext * and a JSScript at my disposal. How can I get the page source code for this page? One answer is get the filename from the script. That is great if its a local filename such as c:\myWebPage.html as I can open that using fopen() etc. However if its a non-local file such as http://someWebAddress/page.html or one of the chrome:// pages then I can't open that. I don't want to fetch the page myself as the page conten...

How to get new web app to use .NET 2.0 on Win2K server using .NET 1.1 as default framework?
I have .net framework1.1 and 2.0 on our server running win2K. i have existing applications that uses asp.net 1.1, i also have a new app that use ASP.net 2.0.  how can i set my new .NET 2.0 app to point to asp.net 2.0 without messing up my existing .NET 1.1 apps? To specify the ASP .Net version fro a web application, do the followingIn IIS Manager select the web application -> Properties -> ASP.Net TabSelect  ASP.Net version you want to use for the applicationRegards,PrashantDont forget to click "Mark as Answer" on the post that helped you. But I am running Win2K...

How can i use javasrcipt or xmlhttprequest to get the image outputed by an aps.net web page?
How can i use javasrcipt or xmlhttprequest to receive the image outputed by an aps.net web page? the webpage like this  protected void Page_Load(object sender, EventArgs e)    {        string strQueryFileName = Request.QueryString["filename"];         string strLocalPath = Server.MapPath(path);        Bitmap  theReturnImage = new Bitmap(strLocalPath);         theReturnImage.Save(ms, ImageFormat.Jpeg); &n...

Do not get expected WEb page on secondary
netware 6.5 sp2 Have setup a web page on a seconary IP address Load appache with the following command line LOAD ADDRESS SPACE = CSMI APACHE2 -f SYS:APACHE2\CSMI\SERVER\HTTPD.CONF Where HTTPD.CONF is set up to Listen 172.16.212.2:80 which is a secondary ip address A display secondary ipaddress at the server lists the seconary ipaddress I can ping the secondary ip address from the client in Remote manager using IP Address management the secondary IP addresses are not listed When I attempt to brose to the HTTP://172.16.212.2 address I do not see the web page I...

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...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

How to use document.getElementById() to get a div in a web page using masterpage?
My scenario is when loading a page, dim out the background and show the progressbar in a popup panel until finishing page load. My problem is that document.getElementById('ctl00_ContentPlaceHolder1_Label1') work fine but document.getElementById('page_backgnd') can't. neither document.getElementById('progressBar').it is strange to me that they can pass the compilor of Vs2005&vs2008. if I use document.getElementById('ctl00_ContentPlaceHolder1_page_backgnd') or document.getElementById("<% =page_backgnd.ClientID %> "), they don't even ...

used a c#.net to vb.net converter and am now getting a syntax error.
ok I used a cool utility at http://www.kamalpatel.net/ConvertCSharp2VB.aspx to convert some c#.net to vb.net and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

C#.NET WEB APPLICATION
hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

Both C# ASPX pages and VB.NET ASPX in single VB.NET Web Applcation Template
Hi.. Is it possible to have both c# pages and VB pages in same Webapplication, what i chose is VB.NET Web application Template. With Thanks, Jaya.... I don't see why you couldn't, but for the sake of consistency I don't know why you would want to do this. When you choose a C# or VB.NET application template(I'm assuming you're using VS or WebMatrix), it simply creates a .aspx file that includes a page directive that specifies the page language. If you created a C# template but want to use VB.Net instead, you need to go from: <%@ Page Language="C#" .... to...

Web resources about - need to use confirm boxes in a C# web page - asp.net.getting-started

Facebook Australia Confirms Interim Director Of Commercial Development And Sales
Facebook confirmed that Sales Director Liam Walsh has been serving and will serve as interim director of commercial development and sales 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 ...

Facebook Confirms 200 Million Active User Mark
Just seven months after hitting the 100 million user mark last August and 90 days after hitting the 150 million mark in January, Facebook confirmed ...

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 ...

'How to Train Your Dragon' Character Comes Out as Gay, Director Confirms - YouTube
'How to Train Your Dragon' Character Comes Out as Gay, Director Confirms In the upcoming animated sequel to "How to Train Your Dragon," the rugged ...

BP confirms TNK stake to be sold
BP is in advanced discussions with the Russian state-controlled oil company Rosneft over the sale of the British company's stake in the troublesome ...

Mexican authorities confirm burnt-out van with two bodies belongs to missing Australian surfers
Mexican authorities confirm a burnt-out van with two bodies did belong to two missing West Australian surfers.

Bugatti confirms new Chiron to debut in Geneva
Filed under: Geneva Motor Show , Bugatti , Supercars Bugatti confirmed the Veyron's highly anticipated successor will be called the Chiron and ...

Microsoft confirms the Windows 10 November Update WAS pulled and this is why
Over the weekend we spotted that the Windows 10 November Update (aka Threshold 2) had been removed from the Media Creation Tool (MCT), and had ...

Mark Hamill confirms he’ll be back as Luke Skywalker in Star Wars: Episode VIII
... about Luke's fate in the upcoming movie, which opens December 18th. Luke isn't even on the film's official poster. But Hamill just confirmed ...

Resources last updated: 12/1/2015 4:57:07 PM