473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

Similar topics

3
by: sentinel | last post by:
Hi, Wonder if anyone can help with this problem: I am using an app with several pages, using a session to track vars between the pages, and using an image map to re-direct back and forwards...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
6
by: MooreSmnith | last post by:
When I navigate to the next page using Response.Rediect("MyNextPage.aspx") current page Page_Load event is called. What I may wrongly understood is that post back will happen whenever there is any...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
7
by: Tom wilson | last post by:
I have created a very simple example that doesn't work. Form1 contains a textbox and a button: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
5
by: Simon Benson | last post by:
Probably a fairly simple problem but one that's been plaguing me for a couple of days... can anyone help? I have a classic ASP page with a number of text boxes which are updatable. For...
5
by: sumeetmakkar | last post by:
Hi all, I am a begineer and working on a project. Facing trouble linking a submit buuton to a page of my choice.Script i am using is: <SCRIPT language=JavaScript><!-- function validate(form) {...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.