Problem in page Redirect
-
Hello Friends, I have a problem in redirect a page.i m using C#.net 2005 .i hv a dropdown list which is bind data from database Like State when i m selecting an item in dropdownlist then the corrospondin District should be come in the second dropdownlist. butit never comes.. there is a problem comes"The specified URL can not be found" I m writing the code below for beter understand. I m also set the Autopostback property =true in dropdownlist. protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { con.Open(); SqlCommand com = new SqlCommand("select State from StateInfo order by StateName asc", con); dr = com.ExecuteReader(); while (dr.Read() == true) { drp_regionname.Items.Add(dr[0].ToString()); } dr.Close(); } } protected void drp_regionname_SelectedIndexChanged(object sender, EventArgs e) { string RegionName = drp_regionname.SelectedValue.ToString(); SqlCommand com1 = new SqlCommand("select district from DistrictInfo where StateName ='" + RegionName + "'", con); con.Open(); dr = com1.ExecuteReader(); while (dr.Read()) { drp_unitname.Items.Add(dr[0].ToString()); } dr.Close(); con.Close(); } This code is running fine in local server but not running in Remote server.. Plz help me....... Thanks ...
-
Hello Friends, I have a problem in redirect a page.i m using C#.net 2005 .i hv a dropdown list which is bind data from database Like State when i m selecting an item in dropdownlist then the corrospondin District should be come in the second dropdownlist. butit never comes.. there is a problem comes"The specified URL can not be found" I m writing the code below for beter understand. I m also set the Autopostback property =true in dropdownlist. protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { con.Open(); SqlCommand com = new SqlCommand("select State from StateInfo order by StateName asc", con); dr = com.ExecuteReader(); while (dr.Read() == true) { drp_regionname.Items.Add(dr[0].ToString()); } dr.Close(); } } protected void drp_regionname_SelectedIndexChanged(object sender, EventArgs e) { string RegionName = drp_regionname.SelectedValue.ToString(); SqlCommand com1 = new SqlCommand("select district from DistrictInfo where StateName ='" + RegionName + "'", con); con.Open(); dr = com1.ExecuteReader(); while (dr.Read()) { drp_unitname.Items.Add(dr[0].ToString()); } dr.Close(); con.Close(); } This code is running fine in local server but not running in Remote server.. Plz help me....... Thanks ...
Could explain where is the problem ? Where are you redirecting to another page ? drp_unitname drop down list is not getting populated with items ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Hello Friends, I have a problem in redirect a page.i m using C#.net 2005 .i hv a dropdown list which is bind data from database Like State when i m selecting an item in dropdownlist then the corrospondin District should be come in the second dropdownlist. butit never comes.. there is a problem comes"The specified URL can not be found" I m writing the code below for beter understand. I m also set the Autopostback property =true in dropdownlist. protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { con.Open(); SqlCommand com = new SqlCommand("select State from StateInfo order by StateName asc", con); dr = com.ExecuteReader(); while (dr.Read() == true) { drp_regionname.Items.Add(dr[0].ToString()); } dr.Close(); } } protected void drp_regionname_SelectedIndexChanged(object sender, EventArgs e) { string RegionName = drp_regionname.SelectedValue.ToString(); SqlCommand com1 = new SqlCommand("select district from DistrictInfo where StateName ='" + RegionName + "'", con); con.Open(); dr = com1.ExecuteReader(); while (dr.Read()) { drp_unitname.Items.Add(dr[0].ToString()); } dr.Close(); con.Close(); } This code is running fine in local server but not running in Remote server.. Plz help me....... Thanks ...
from ur code it seems u r not redirecting ur page anywhere. the same page is posted back. As far as the URL not found error , check the "REDIRECT" code u have written and see whether the target page u r specifying exists in ur website. could u post the conn string info as well as the redirect section of ur code. Regards, Rajeesh Did u know-Maths Illiteracy affects 9 out of 7 people
-
Hello Friends, I have a problem in redirect a page.i m using C#.net 2005 .i hv a dropdown list which is bind data from database Like State when i m selecting an item in dropdownlist then the corrospondin District should be come in the second dropdownlist. butit never comes.. there is a problem comes"The specified URL can not be found" I m writing the code below for beter understand. I m also set the Autopostback property =true in dropdownlist. protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { con.Open(); SqlCommand com = new SqlCommand("select State from StateInfo order by StateName asc", con); dr = com.ExecuteReader(); while (dr.Read() == true) { drp_regionname.Items.Add(dr[0].ToString()); } dr.Close(); } } protected void drp_regionname_SelectedIndexChanged(object sender, EventArgs e) { string RegionName = drp_regionname.SelectedValue.ToString(); SqlCommand com1 = new SqlCommand("select district from DistrictInfo where StateName ='" + RegionName + "'", con); con.Open(); dr = com1.ExecuteReader(); while (dr.Read()) { drp_unitname.Items.Add(dr[0].ToString()); } dr.Close(); con.Close(); } This code is running fine in local server but not running in Remote server.. Plz help me....... Thanks ...
Your code is filling drop down from database on PageLoad, if region name selection changes, it inserts additional data from the db (not clearing previous data from the drop down!, is it what you want?) I don't see any redirection at all! However, few tips: 1. in sqlcommand, always use Parameters instead of concatenated strings as a query, to prevent sql injection (security flaw): SqlCommand com1 = new SqlCommand("select district from DistrictInfo where StateName = @RegionName", con); com1.Parameters.Add(new SqlParameter("@RegionName", RegionName)); 2. be sure you are closing connection to database when you don't need it anymore 3. use 'using' clause when possible, to ensure your IDisposible objects are going to be disposed in all cases (no need to call dr.Close(), as it is going to be called in Dispose() method: using (dr = com1.ExecuteReader()) { while (dr.Read()) { drp_unitname.Items.Add(dr[0].ToString()); } } 4. use exception handling, try {...} catch {...} blocks, at least in event handlers