468,733 Members | 1,545 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

Page redirect after submit button has been clicked

17
I have a form that I want to redirect to another page after clicking the submit button. It works well (please see the code below) except that it cancells my pop-up message, it goes the redirected page without showing the popup. Please help:


Expand|Select|Wrap|Line Numbers
  1. private void Submit_Click(object sender, System.EventArgs e)
  2. {
  3.    if( filMyFile.PostedFile.ContentLength != 0 )
  4.        {
  5.  
  6.     string strFilename;  
  7.                 strFilename = filMyFile.PostedFile.FileName;    
  8.                 strFilename =    System.IO.Path.GetFileName(strFilename);
  9.  
  10.     filMyFile.PostedFile.SaveAs(@"C:\Advert_images\"+strFilename);
  11.          }
  12.            else
  13.     {
  14.         // No file
  15.  
  16.  
  17.     }
  18.  
  19.  
  20. string status;
  21. string image_name;  
  22. image_name = filMyFile.PostedFile.FileName;
  23. image_name = System.IO.Path.GetFileName(image_name);
  24. status = "unverified";    
  25. SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
  26. SqlCommand cmd =  new SqlCommand("Add_advert_new", con);
  27. cmd.CommandType = CommandType.StoredProcedure;
  28. con.Open();
  29. cmd.Parameters.Add("@Title",SqlDbType.VarChar);
  30. cmd.Parameters["@Title"].Value = txtTitle.Text;
  31. cmd.Parameters.Add("@Expiry_date",SqlDbType.DateTime);
  32. cmd.Parameters["@Expiry_date"].Value = Session["SelectedDate"].ToString();
  33. cmd.Parameters.Add("@Description",SqlDbType.Text );
  34. cmd.Parameters["@Description"].Value = txtDescr.Text;
  35. cmd.Parameters.Add("@Added_by",SqlDbType.VarChar );
  36. cmd.Parameters["@Added_by"].Value = Session["Name"].ToString();
  37. cmd.Parameters.Add("@Surname",SqlDbType.VarChar );
  38. cmd.Parameters["@Surname"].Value = Session["SName"].ToString();
  39. cmd.Parameters.Add("@status",SqlDbType.VarChar );
  40. cmd.Parameters["@status"].Value = status;
  41. cmd.Parameters.Add("@image_name",SqlDbType.VarChar );
  42. cmd.Parameters["@image_name"].Value = image_name;
  43.  
  44. cmd.ExecuteNonQuery();
  45. con.Close();
  46.  
  47. Response.Write(@"<script language='javascript'>alert('Advert has been uploaded but it will be verified by the webmaster fisrt before it can be displayed. Have a nice day!')</script>");
  48.  
  49.  
  50.  
  51. SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["EmailServer"];
  52.             string strTo = "MicheleH@int.scm";
  53.             string strFrom = "webmaster@int.scm";
  54.  
  55.             string strSubject = "New advert to be verified";
  56.  
  57.             SmtpMail.Send(strFrom, strTo, strSubject,
  58.                 "A new advert has been loaded, please click on the link http://jhb-ds-web1/scmnet/doc/verifyadverts.aspx  to verify the advert.");
  59.  
  60.  
  61. Response.Redirect("classifieds_1.aspx");
  62. }
May 15 '09 #1
1 5634
Bassem
344 100+
The only reason I know that ASP.NET events take action first (higher priority), I maybe mistaken. To solve this problem you have to set both actions in the same priority so do the redirect using JavaScript instead of ASP.NET.
Expand|Select|Wrap|Line Numbers
  1.         Response.Write(@"<script language='javascript'>alert('Advert has been uploaded but it will be verified by the webmaster fisrt before it can be displayed. Have a nice day!')</script>");
  2.  
  3.         Response.Write(@"<script language='javascript'>window.location = 'http://www.google.com'</script>");
  4.  
It should works fine if not please tell me.
May 15 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by sentinel | last post: by
2 posts views Thread by John Lau | last post: by
6 posts views Thread by MooreSmnith | last post: by
7 posts views Thread by Tom wilson | last post: by
6 posts views Thread by scottyman | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.