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

12 Replies
5098 Views

Similar Articles

[PageSpeed] 8

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:

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