Show Confirm dialog box in C# web application

Hi all

 I want to show a message box like confirm dailog box after comairing that customer alredy exist in database and message will say "Do you want to overwrite customer data?". if "ok" is clicked then customer data will overwrite otherwise not. I know about javascript:confirm("Are you sure to overwrite?") but this will popup when we clicked on the link button like this

lnkImport.Attributes.Add("onclick", "return Overwrite();");

function Overwrite()

{

if (confirm("Are you sure you want to overwrite customer detail?")==true) return true;

else

return false;

}

 

But in my case i wnat to show confirm dialoge box during the process is going on, means first i look for weather customer already exist or not and if exist the confirm message will display

For this i used

 

public void MesssageBox()

{

if (System.Windows.Forms.MessageBox.Show("Customer data already exists. Do you want to overwrite it?.", "Overwrite", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Asterisk, System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.OK)

{

//System.Console.WriteLine("OK Clicked");

Exist = 3;

ImportCustomerData();

}

}

This is working fine on local machine but not on server giving following msg:

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation.
Specify a Servernotification or Default DesktopOnly style to display a notification from server application.
 

 

Pls rply soon

 


Anil
0
anildbest83
2/6/2008 12:42:54 PM
asp.net.client-side 24353 articles. 2 followers. Follow

12 Replies
6759 Views

Similar Articles

[PageSpeed] 52

You can't run a WinForms message box in a web page! I posted this solution yesterday or a few days ago for the almost exact same question:
     http://forums.asp.net/t/1213430.aspx

You should always look at similar posts before posting a question.

NC...

1
NC01
2/6/2008 1:07:30 PM

I hav seen your post alredy but didn't got any solution from that

using your code display only "\n\n" on the form not any message box

thkx for your help


Anil
-1
anildbest83
2/7/2008 2:49:50 PM

Well it seems to work for everyone but you, and I don't know what you are doing different. Post some of the code.

NC...

-1
NC01
2/7/2008 3:14:32 PM

Here is the code 

 

#region
Page Loadprotected void Page_Load(object sender, EventArgs e)

{

try

{

Page.ClientScript.GetPostBackEventReference(this, string.Empty)if (!Page.IsPostBack)

{

string eventTarget;

if ((Page.Request["__EVENTTARGET"] == null))

{

eventTarget =
string.Empty;

}

else

{

eventTarget = Page.Request[
"__EVENTTARGET"];

}

string eventArgument;if ((Page.Request["__EVENTARGUMENT"] == null))

{

eventArgument =
string.Empty;

}

else

{

eventArgument = Page.Request[
"__EVENTARGUMENT"];

}

if ((eventTarget == "UserConfirmationPostBack"))

{

if ((eventArgument == "True"))

{

//User said to go ahead and do it...

Label3.Text = "You clicked YES - added after confirm during page load";

}

else

{

Label3.Text =
"You clicked NO - added after confirm during page load";

}

}

}

lnkDeleteCustomer.Attributes.Add(
"onclick", "return confirm_delete();");lbtnDeleteProposal.Attributes.Add("OnClick", "return deleteProposal();");

}

catch (Exception ex)

{

}

}

#endregion

protected void btnUpload_Click(object sender, EventArgs e)

{

ImportCustomerData();

}

protected void ImportCustomerData()

{

try

{

if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength <= 7000000)

{

String UploadedFile = FileUpload1.PostedFile.FileName;

int ExtractPos = UploadedFile.LastIndexOf("\\") + 1;

String UploadedFileName = UploadedFile.Substring(ExtractPos, UploadedFile.Length - ExtractPos);

Int32 Name_Lenght = UploadedFileName.Length;

Int32 Ext_Index = (UploadedFileName.LastIndexOf("."));

string ext = UploadedFileName.Substring(Ext_Index, Name_Lenght - Ext_Index);

DirectoryInfo Dir = new DirectoryInfo(Request.PhysicalApplicationPath + "TemproaryFiles");if (!Dir.Exists)

{

Directory.CreateDirectory(Request.PhysicalApplicationPath + "TemproaryFiles");

}

string gid = System.Guid.NewGuid().ToString();

string MyString = gid + ext;

string folderName = Request.PhysicalApplicationPath + "TemproaryFiles";

FileUpload1.PostedFile.SaveAs(folderName + "/" + MyString);

string File = Request.PhysicalApplicationPath + "TemproaryFiles" + "/" + MyString;

string statusMessages = "";

OleDbConnection cnCSV = new OleDbConnection();

string ConnectionString = "";

if (ext == ".xlsm" || ext == ".xls")

{

ConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + File + @";Extended Properties=""Excel 12.0;HDR=Yes;""";

lblFile.Visible = false;

try

{

ProcessCustomerGlobals(ConnectionString);//"If customer already exists then Exist = 2"

if (Exist == 1)

{

lblImportStatus.Text =
"Customer data can not be imported because this customer already exist for other user.";

}

else if (Exist == 2)

{

// MesssageBox();

bool isConfirmNeeded = true;

string confirmMessage = "This is the message, yes or no";

string scriptKey = "test";if ((isConfirmNeeded))

{

System.Text.StringBuilder javaScript = new System.Text.StringBuilder();

javaScript.Append("\\n<script type=text/javascript>\\n");

javaScript.Append("<!--\\n");

javaScript.Append("var userConfirmation = window.confirm('Customer data already exists. Do you want to overwrite it?.');\\n");

javaScript.Append("__doPostBack('UserConfirmationPostBack', userConfirmation);\\n");

javaScript.Append("// -->\\n");

javaScript.Append("</script>\\n");

Page.ClientScript.RegisterStartupScript(this.GetType(), scriptKey, javaScript.ToString());

}

}

else if (Exist == 3)

{

lblImportStatus.Text =
"Customer data imported successfully.";

}

}

catch (OleDbException ex)

{

lblImportStatus.Text =
"Processing: Customers: An error occurred while reading the input file '" + UploadedFileName + "' - " + ex.Message + "\r\n\r\n";

}

catch (IndexOutOfRangeException rangeEx)

{

lblImportStatus.Text =
"Processing: Customers: The file '" + UploadedFileName + "' appears to be an incorrect format - the " +

rangeEx.Message + " column was not found\r\n\r\n";

}

try

{

if (Exist == 4)

{

lblImportStatus.Text =
"Customer data importing canceled.";

}

 


Anil
-1
anildbest83
2/8/2008 4:20:04 AM

 use the code like this.it will be done when the process is going on

 

page.Clientscript.Registerstartupscript(Gettype(),"js","<script>Are you sure you want to overwrite customer detail?</script>"); 


If debugging is the process of removing bugs, then programming must be the process of putting them in.

Suriya
1
suriyamail001
2/8/2008 4:23:38 AM

Hi,

I think you cannot do like this..... you follow the below method....

1. Check whether details are existing already...

2.if not, insert the details...

3.If yes, try the below code

Page.ClientScript.RegisterStartUpScript(this.GetType(),"Confi","if(Confirm('Are you sure want to overwrite?')  == true){ window.location.href='update.aspx';}else{return false;}",true);

4. In update.aspx page load you can write the code to overwrite the details by sending the necessary details. 

 

Thanks.... 


Vasanthakumar
Software Engineer.
-1
vasanth
2/8/2008 4:43:04 AM

Hi

Page.ClientScript.RegisterStartUpScript(this.GetType(),"Confi","if(Confirm('Are you sure want to overwrite?')  == true){ window.location.href='update.aspx';}else{return false;}",true);

not working, not shown any confirm message box

I m using modal popup to upload file and i seems this may be the problem

Pls rply

Thankx


Anil
1
anildbest83
2/8/2008 8:32:59 AM

just write this code in code behind on pageload:

 

btn_delete.Attributes.Add("onclick","javascript:return confirm('Are You Sure To Delete This Category')");

 
 
Don't forget to click "Mark as Answer" on the post that helped you.
This will help readers to know which post solved your issue and make their search easy
-1
roopsi_saxena
2/8/2008 11:34:56 AM

rooopsi ji, i already mentioned that i don't require to show msg on click event, i need to show something in between the process is going on

thankx for ur rply


Anil
1
anildbest83
2/8/2008 12:03:32 PM
Anil jiiiiiiiiiii

oh.....i m sorry to reply u by reading ur subject of problem only..(without understanding your  problem)...................

-1
roopsi_saxena
2/8/2008 12:51:27 PM

anildbest83:

Page.ClientScript.RegisterStartUpScript(this.GetType(),"Confi","if(Confirm('Are you sure want to overwrite?')  == true){ window.location.href='update.aspx';}else{return false;}",true);

not working, not shown any confirm message box

I m using modal popup to upload file and i seems this may be the problem

 

Hi anildbest83,

For AJAX partial postback, we should use “ScriptManager.RegisterStartupScript” instead of “Page.ClientScript.RegisterStartupScript”. I have replied the similar issue in the following thread, please check it at your convenience.

RegisterStartupBlock doesn't fires after Updatepanel Refresh
http://forums.asp.net/t/1125176.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
2/12/2008 10:01:25 AM

Benson Yu - MSFT:

anildbest83:

Page.ClientScript.RegisterStartUpScript(this.GetType(),"Confi","if(Confirm('Are you sure want to overwrite?')  == true){ window.location.href='update.aspx';}else{return false;}",true);

not working, not shown any confirm message box

I m using modal popup to upload file and i seems this may be the problem

 

Hi anildbest83,

For AJAX partial postback, we should use “ScriptManager.RegisterStartupScript” instead of “Page.ClientScript.RegisterStartupScript”. I have replied the similar issue in the following thread, please check it at your convenience.

RegisterStartupBlock doesn't fires after Updatepanel Refresh
http://forums.asp.net/t/1125176.aspx

Which is what it says here also http://forums.asp.net/t/1213430.aspx which is the link that I originally posted.

NC...

 

1
NC01
2/12/2008 3:53:20 PM
Reply:

Similar Artilces:

How do I have a web based Client Side Application in .net?
 Is there any way to do this in .net?  Have a Client Side Web Based Client Side application.  similar to Page Designers in VB6? Is it possible?  ORLets say your app was server side but the client lost network connection somehow how would you take the data in the form and resend it when the server came back?   Rico Rodriguez Doesn't really work like that. Most web applications are stateless, but with ASP.NET you can do things to help with that. If someone wanted to run ASP.NET on their client, they'd have to have IIS installed - something most u...

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 show "Save changes?" warning after client-side changes in a web-application?
We have a complex web application with a main-menu and sub-menu of tab folders; each tab-folder shows a different screen. Suppose the user selected tab folder A, got the A screen and changed a number in a textbox. Now the user clicks the tab folder B and instead of geting the B screen, the user should get a warning "Save your changes?"On "yes" - save the changes in the A screen and show B, on "no" - discard the A changes and show B. How to do this?   Thanks! Persist the values in the TAB A in a variable(say X), depending on yo...

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

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

Converting windows application using web service from Visual C#.net 2003 to Visual Studio.net 2005
Hello, everyone! I have a solution which contains a windows project,a web service project and several other library projects. These projects were coded under visual c#.net 2003. Now I need to converted them to use Visual Studo.net 2005. Does any one know any article providing step-by-step guide  to converting WINDOWS APPLICATION with web service? I can find one under MSDN for converting web project.  But I guess I am a little confused if mine should follow this article since I am using web service in my windows application? Thanks a lot in advance.  ...

C#.NET in VS.NET vs. C# in Web Matrix
Hi all, I am very new to .NET ... I realized C#.NET is only available from Visual Studio.NET ... however, I realized Web Matrix also allowed us to choose C# as language but not C#.NET ... they are not the same, right? If not, then why it's in Web Matrix which runs ASP.NET?? If I need to run C#.Net, I MUST GET VS.NET, right? Can C#.NET has the abality to create chat program? Thank you very much. C#.NET and C# are the same thing. JimMS MVP ASP.NET [VC++/MFC emeritus]Old Dog Learns New TricksPreferred programming language: cuneiform on clay tablets So ... that means I can use web matrix t...

Client Side Web based Applications
I've already installed the Framework on the server. The IIS was already installed in this server. My question is: Is it necessary that the framework be installed on the client side to run .NET web-based applications? Thanks nope..asp.net spits out html pages so the client need not have any framework installed on his machine..if he wants to RUN aspx pages only then he would need framework installed.. hth***********************Dinakar NethiLife is short. Enjoy it.*********************** No, if you only create ASP.NET websites all the client needs is a browser. If you want to ru...

printer dialog box in web application
Hi experts, I need to know how do I manage printer by create a dialog box that can selectprinter, choose page range , page size and number of copies. Please giveme an example of code in asp.net programming How about using JavaScript's window.print();Thanks,MaxLet Me Google That For You! hi, check this out http://www.devarticles.com/c/a/C-Sharp/Printing-Using-C-sharp/5/ just search on google and u will get lot of answers for ur questionMuch Obliged & Thanks a Lot,Myself Why you need to re-invent the wheel? You can use the default printer dialog box used in each...

Client side web application deployment
Hi All, I would like to know what software is required on client computer to run web application in the following environment: Server side: Windows 2000 server IIS/ASP.NET SQL Server 2000 VS .NET 2002 Client side: Windows XP Pro Windows XP Home Windows 2000 Pro For some reason, some data and images on web pages are not rendered on the client browser while they appear normally on the server browser. Any help is appreciated. chokk Only a browser is required. However websites are developed that specifically require Internet Explorer. Thanks for your prom...

Using .net AJAX enabled application in non .net Web Application
Hi,Does anyone have similar experience in development?  I want to check if it's possible to run .net ajax object (from one standalone .net framework platform in company) with non .net application (i.e. J2EE web application)?  It is because we want to add certain feature (i.e. office communicator chat) to our exist application (oracle J2ee). Please give me some advice :) Thanks! Hi, .Net AJAX is based on .Net Framework architecture. Thus .Net Framework currently lacks support for other platforms, such as Java. Please check this link: http://www.csharphelp.com/arch...

Converting a VS 2005 Web Application to a VS .NET 2003 Web Application
Well it seems that I am going against the stream here, but one of our clients wants the web application I wrote in Visual Studio 2005 to be deployed using Visual Studio .NET 2003. What's the best way to go about this without rewriting the whole dang thing? I would probably create a new 2003 project, copy all of your aspx and other files into it, attempt a build and see what happens.  If you didn't use a lot of the new controls (like membership, personalization, masterpages etc, then you will probably be ok with just minor changes.  If you did rely on a lot of the newer c...

Calling a web service in client side C#
Hello,  I am trying to call a web service in client side C# code, having it as a datasource on the page to use. I cannot have a codebehind file due to limitations. Does anyone know how to do this or have suggestions?  Thanks! What do you mean by "client side C#"? -- "Mark As Answer" if my reply helped you -- Hi check this link http://aspdotnetcodebook.blogspot.com/2008/04/how-to-call-webservice-with-aspnet-ajax.html   if you have any problem.. feel free to contact.     "Mark As Answer" If my reply helped you Santosh kuma...

message box showing on client web page
Hi: I am trying to find a similar message box as MS Access such as:              if txtFirstName = "" or txtlastName="" or txtPhoneNum = "" Then                Msgbox ("please input all the text boxes")               End If But I can't find any message box in Asp.net2.0, should have, but I can't find it. Thanks for your help. Jt   ...

Web resources about - Show Confirm dialog box in C# web application - asp.net.client-side

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Welfare experiment may have applications in Australia
A trial in Finland providing an obligation-free basic income could change how we think about welfare.

Apple patent application reveals exciting possibilities for twin-camera system rumored for iPhone 7
We heard a report in November that Apple was testing an iPhone 7 model with dual rear cameras , and a patent application published today not ...

Seagate Introduces First 8 TB Hard Disk Drive for Consumer NAS Applications
Seagate Technology on Tuesday introduced its new breed of hard disk drives (HDDs) for network area storage (NAS) and RAID applications. The new ...

Panasonic Develops a Stretchable Resin Film and Its Application Materials for Stretchable Electronics ...
A stretchable film is developed. This film stretches to 2.5 times the original length and then returns to the original form. A conductive paste ...

MBA: Mortgage Applications Decreased Over Two Week Period in Latest MBA Weekly Survey, Purchase Applications ...
From the MBA: Mortgage Applications Decreased Over Two Week Period in Latest MBA Weekly Survey Mortgage applications decreased 27 percent from ...

Mortgage applications rebound
Mortgage applications increased 21.3 percent on a seasonally adjusted basis, for the week ending January 8th, versus previous week,

SURPRISE! Mizzou Sees Application Drop After Days Of Protests, Illusory Klan Hoods, Poop Swastika
SURPRISE! Mizzou Sees Application Drop After Days Of Protests, Illusory Klan Hoods, Poop Swastika

In Application To Move To Los Angeles, Rams Shit All Over City Of St. Louis
... to relocate to the greater Los Angeles metropolitan area. The relocation would be effective for the 2016 NFL League Year.” The Rams’ full application ...

Panasonic touch panel production to be solely for vehicle applications by 2020, says report
Panasonic is aiming to transfer its touch panel production completely to vehicle applications by 2020 in order to meet increasing demand for ...

Resources last updated: 1/15/2016 3:32:41 AM