0

I am used message box in visual studio 2010. It works in debug mode but does not work on the server. Why does it not work?

if (MessageBox.Show("Invoice sample already exists. Do you want to overwrite it?.", "Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification) == DialogResult.OK)
{

    dr.Close();
    con.Close();
    con.Open();
    cmd = new SqlCommand("sp_pdm_shopping_upload_update", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add(new SqlParameter("@sample", SqlDbType.Char, 10));
    cmd.Parameters.Add(new SqlParameter("@image", SqlDbType.Image));
    cmd.Parameters.Add(new SqlParameter("@type", SqlDbType.Char, 10));
    cmd.Parameters["@sample"].Value = txt_code.Text;
    cmd.Parameters["@image"].Value = imgbyte;
    cmd.Parameters["@type"].Value = "INV";
    cmd.ExecuteNonQuery();
    con.Close();
    //getuploadinvoice();
    //getuploadimage();
    ErrorMsg.Visible = true;
    ErrorMsg.Text = "The image has been successfully updated.";


}
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
jintha arun
  • 31
  • 1
  • 10
  • Is this an ASP.NET application? Your tags suggest it is... If so, why are you using message boxes? Which terminal would you expect them to show up on? – Chris Shain May 25 '12 at 14:44
  • yes visual studio 2010 ..i am used system.windows.forms assemly and namespace..but working on my system and debug time..but hosting the project does not show the message box ...suggest me – jintha arun May 25 '12 at 14:47
  • i want overwrite the image so i want message box in yes or no option click the yes means execute the code and upload the image .do not overwrite the image means click the no and leave out the code – jintha arun May 25 '12 at 14:52
  • Then you need to do that in Javascript. Google for "javascript confirmation popup". Even if messagebox worked, it will show up on the server, not the client. – Chris Shain May 25 '12 at 14:55

2 Answers2

1

On your HTML button you should put a javascript code. For example:

<input type="button" value="Save" onclick="return confirm('Invoice sample already exists. Do you want to overwrite it?.')" />

Then in your server side just act normally. Only the users who accepted the dialog box should reach your server side function.

Adrian Salazar
  • 5,279
  • 34
  • 51
0

Of course it doesn't show up. You are not guaranteed to even have a terminal on which to show a message box from an ASP.NET application. They are intended only for windows client applications, not web applications.

Instead of using a message box, write your debug info to a log file instead. If you google for it you'll find many examples of how to do that.

If you need user confirmation, as it appears from the comments, then use a javascript confirmation dialog as @AdrianSalazar suggests in his answer.

Chris Shain
  • 50,833
  • 6
  • 93
  • 125
  • Microsoft's Enterprise Library contains a good logging block that can be rather useful. – Mark May 25 '12 at 14:53