D
Dan
Hi, I'm going crazy here, please help. I have a parent page that has a
user control on it that bubbles up data from a dropdown menu. The drop
down menus are populated by a set of radio buttons, each populates the
drop downs with unique data. All works well, you check a radio button
and the onbubbleevent fires loading the drop downs. A user can then
select an item from the drop down and be forwarded (Respose.Redirect)
to the appropriate detail page.
Here is the problem. If the user goes to a detail page, then uses the
browser back button and goes back to the main page, selects a
differnet radio button, the onbubbleevent fires before the drop downs
are populated with the corresponding radio button data. This results
in an error because the drop downs have the wrong data for the
selected radio button.
I tried to just prevent the page from caching, but that resulted in a
"Warning: Page has Expired" window which I really don't like. It seems
like this should be easy, I just need the radio button function to
always fire first! The wierd thing is that I test to see if the sender
is a drop down menu in the bubble event and it still fires when a
radio button is selected (only when someone uses the browser back
button after selecting an item from one of the drop downs). Please
help, code is below.
Thanks
This is the Main Parent page:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace MyPage
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected RadioButton Btn1, Btn2, Btn3, Btn4;
protected MyPage.dropdownsearch SearchMenus;
protected string TheId, ButtonOn, LastButtonOn;
protected MyPage.globalnav MenuItems;
protected HyperLink ResourceUrl;
private void Page_Load(object sender, System.EventArgs e)
{
}
protected override bool OnBubbleEvent(object sender, EventArgs e)
{
if(sender != null && sender is DropDownList)
{
DropDownList temp = (DropDownList)sender;
if(temp.ID.Equals("TradeNames"))
{
TheId = "TradeNames="+SearchMenus.TradeNames.SelectedItem.Value;
ForwardThePage();
}
if(temp.ID.Equals("Applications"))
{
TheId = "Applications="+SearchMenus.Applications.SelectedItem.Value;
ForwardThePage();
}
if(temp.ID.Equals("Processes"))
{
TheId = "Processes="+SearchMenus.Processes.SelectedItem.Value;
ForwardThePage();
}
}
return true;
}
protected void ForwardThePage()
{
if (Btn1.Checked)
{
Response.Redirect("btn1/index.aspx?"+TheId);
}
if (Btn2.Checked)
{
Response.Redirect("btn2/index.aspx?"+TheId);
}
if (Btn3.Checked)
{
Response.Redirect("btn3/index.aspx?"+TheId);
}
if (Btn4.Checked)
{
Response.Redirect("btn4/index.aspx?"+TheId);
}
}
protected void CategorySelected(object sender, System.EventArgs e)
{
if (Btn1.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=1";
SearchMenus.SqlCat = "1";
SearchMenus.DbCall();
}
if (Btn2.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=2";
SearchMenus.SqlCat = "2";
SearchMenus.DbCall();
}
if (Btn3.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=4";
SearchMenus.SqlCat = "3";
SearchMenus.DbCall();
}
if (Btn4.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=3";
SearchMenus.SqlCat = "4";
SearchMenus.DbCall();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
This is the Drop Down User Control:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace MyPage
{
/// <summary>
/// Summary description for tier.
/// </summary>
public class dropdownsearch : System.Web.UI.UserControl
{
SqlConnection SearchConnection;
protected DataSet MyDataSet = new DataSet();
public DropDownList TradeNames, Applications, Processes;
protected string Url;
private string _SqlCat;
protected Label MyLabel;
SqlCommand MyCommand;
public string SqlCat
{
get
{
return _SqlCat;
}
set
{
_SqlCat = value;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
}
}
public void TradeClear(object sender, System.EventArgs e)
{
Applications.SelectedIndex = 0;
Processes.SelectedIndex = 0;
RaiseBubbleEvent(sender, e);
}
public void ApplicationClear(object sender, System.EventArgs e)
{
TradeNames.SelectedIndex = 0;
Processes.SelectedIndex = 0;
RaiseBubbleEvent(sender, e);
}
public void ProcessClear(object sender, System.EventArgs e)
{
Applications.SelectedIndex = 0;
TradeNames.SelectedIndex = 0;
RaiseBubbleEvent(sender, e);
}
public void DbCall()
{
SearchConnection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string MySqlStatement = "sp_DropDownsSql " +SqlCat+", "+SqlCat;
MyCommand = new SqlCommand(MySqlStatement, SearchConnection);
SearchConnection.Open();
SqlDataReader MyReader = MyCommand.ExecuteReader();
TradeNames.DataSource = MyReader;
TradeNames.DataValueField = "TradeId";
TradeNames.DataTextField = "TradeNames";
TradeNames.DataBind();
TradeNames.Items.Insert(0, new ListItem("---------------Search By
Trade Name-------------"));
MyReader.NextResult();
Applications.DataSource = MyReader;
Applications.DataValueField = "ApplicationId";
Applications.DataTextField = "Application";
Applications.DataBind();
Applications.Items.Insert(0, new ListItem("---------------Search By
Application------------"));
MyReader.NextResult();
Processes.DataSource = MyReader;
Processes.DataValueField = "ProcessId";
Processes.DataTextField = "Processes";
Processes.DataBind();
Processes.Items.Insert(0, new ListItem("---------------Search By
Process----------------"));
MyReader.NextResult();
MyReader.Close();
SearchConnection.Close();
TradeNames.SelectedValue = Request.QueryString["TradeNames"];
Applications.SelectedValue = Request.QueryString["Applications"];
Processes.SelectedValue = Request.QueryString["Processes"];
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.TradeNames.SelectedIndexChanged += new
System.EventHandler(this.TradeClear);
this.Applications.SelectedIndexChanged += new
System.EventHandler(this.ApplicationClear);
this.Processes.SelectedIndexChanged += new
System.EventHandler(this.ProcessClear);
}
#endregion
}
}
user control on it that bubbles up data from a dropdown menu. The drop
down menus are populated by a set of radio buttons, each populates the
drop downs with unique data. All works well, you check a radio button
and the onbubbleevent fires loading the drop downs. A user can then
select an item from the drop down and be forwarded (Respose.Redirect)
to the appropriate detail page.
Here is the problem. If the user goes to a detail page, then uses the
browser back button and goes back to the main page, selects a
differnet radio button, the onbubbleevent fires before the drop downs
are populated with the corresponding radio button data. This results
in an error because the drop downs have the wrong data for the
selected radio button.
I tried to just prevent the page from caching, but that resulted in a
"Warning: Page has Expired" window which I really don't like. It seems
like this should be easy, I just need the radio button function to
always fire first! The wierd thing is that I test to see if the sender
is a drop down menu in the bubble event and it still fires when a
radio button is selected (only when someone uses the browser back
button after selecting an item from one of the drop downs). Please
help, code is below.
Thanks
This is the Main Parent page:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace MyPage
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected RadioButton Btn1, Btn2, Btn3, Btn4;
protected MyPage.dropdownsearch SearchMenus;
protected string TheId, ButtonOn, LastButtonOn;
protected MyPage.globalnav MenuItems;
protected HyperLink ResourceUrl;
private void Page_Load(object sender, System.EventArgs e)
{
}
protected override bool OnBubbleEvent(object sender, EventArgs e)
{
if(sender != null && sender is DropDownList)
{
DropDownList temp = (DropDownList)sender;
if(temp.ID.Equals("TradeNames"))
{
TheId = "TradeNames="+SearchMenus.TradeNames.SelectedItem.Value;
ForwardThePage();
}
if(temp.ID.Equals("Applications"))
{
TheId = "Applications="+SearchMenus.Applications.SelectedItem.Value;
ForwardThePage();
}
if(temp.ID.Equals("Processes"))
{
TheId = "Processes="+SearchMenus.Processes.SelectedItem.Value;
ForwardThePage();
}
}
return true;
}
protected void ForwardThePage()
{
if (Btn1.Checked)
{
Response.Redirect("btn1/index.aspx?"+TheId);
}
if (Btn2.Checked)
{
Response.Redirect("btn2/index.aspx?"+TheId);
}
if (Btn3.Checked)
{
Response.Redirect("btn3/index.aspx?"+TheId);
}
if (Btn4.Checked)
{
Response.Redirect("btn4/index.aspx?"+TheId);
}
}
protected void CategorySelected(object sender, System.EventArgs e)
{
if (Btn1.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=1";
SearchMenus.SqlCat = "1";
SearchMenus.DbCall();
}
if (Btn2.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=2";
SearchMenus.SqlCat = "2";
SearchMenus.DbCall();
}
if (Btn3.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=4";
SearchMenus.SqlCat = "3";
SearchMenus.DbCall();
}
if (Btn4.Checked)
{
MenuItems.ResourceUrl.NavigateUrl = "resources.aspx?CatId=3";
SearchMenus.SqlCat = "4";
SearchMenus.DbCall();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
This is the Drop Down User Control:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace MyPage
{
/// <summary>
/// Summary description for tier.
/// </summary>
public class dropdownsearch : System.Web.UI.UserControl
{
SqlConnection SearchConnection;
protected DataSet MyDataSet = new DataSet();
public DropDownList TradeNames, Applications, Processes;
protected string Url;
private string _SqlCat;
protected Label MyLabel;
SqlCommand MyCommand;
public string SqlCat
{
get
{
return _SqlCat;
}
set
{
_SqlCat = value;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
}
}
public void TradeClear(object sender, System.EventArgs e)
{
Applications.SelectedIndex = 0;
Processes.SelectedIndex = 0;
RaiseBubbleEvent(sender, e);
}
public void ApplicationClear(object sender, System.EventArgs e)
{
TradeNames.SelectedIndex = 0;
Processes.SelectedIndex = 0;
RaiseBubbleEvent(sender, e);
}
public void ProcessClear(object sender, System.EventArgs e)
{
Applications.SelectedIndex = 0;
TradeNames.SelectedIndex = 0;
RaiseBubbleEvent(sender, e);
}
public void DbCall()
{
SearchConnection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string MySqlStatement = "sp_DropDownsSql " +SqlCat+", "+SqlCat;
MyCommand = new SqlCommand(MySqlStatement, SearchConnection);
SearchConnection.Open();
SqlDataReader MyReader = MyCommand.ExecuteReader();
TradeNames.DataSource = MyReader;
TradeNames.DataValueField = "TradeId";
TradeNames.DataTextField = "TradeNames";
TradeNames.DataBind();
TradeNames.Items.Insert(0, new ListItem("---------------Search By
Trade Name-------------"));
MyReader.NextResult();
Applications.DataSource = MyReader;
Applications.DataValueField = "ApplicationId";
Applications.DataTextField = "Application";
Applications.DataBind();
Applications.Items.Insert(0, new ListItem("---------------Search By
Application------------"));
MyReader.NextResult();
Processes.DataSource = MyReader;
Processes.DataValueField = "ProcessId";
Processes.DataTextField = "Processes";
Processes.DataBind();
Processes.Items.Insert(0, new ListItem("---------------Search By
Process----------------"));
MyReader.NextResult();
MyReader.Close();
SearchConnection.Close();
TradeNames.SelectedValue = Request.QueryString["TradeNames"];
Applications.SelectedValue = Request.QueryString["Applications"];
Processes.SelectedValue = Request.QueryString["Processes"];
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.TradeNames.SelectedIndexChanged += new
System.EventHandler(this.TradeClear);
this.Applications.SelectedIndexChanged += new
System.EventHandler(this.ApplicationClear);
this.Processes.SelectedIndexChanged += new
System.EventHandler(this.ProcessClear);
}
#endregion
}
}