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; elsereturn 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 |
![]() |
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.aspxYou should always look at similar posts before posting a question.
NC...
![]() |
1 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
Anil jiiiiiiiiiiioh.....i m sorry to reply u by reading ur subject of problem only..(without understanding your problem)...................
![]() |
-1 |
![]() |
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 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.aspxWhich is what it says here also http://forums.asp.net/t/1213430.aspx which is the link that I originally posted.
NC...
![]() |
1 |
![]() |