OnBubbleEvent firing when it's not suppose to

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

}
}
 
Y

Yama

Save each Reader into a Session.

try{
string MySqlStatement;
if(Session["MySqlStatement"] !=null){
MySqlStatement = "sp_DropDownsSql " +SqlCat+", "+SqlCat;
Session["MySqlStatement"] = MySqlStatement ;
}
else MySqlStatement = (string)Session["MySqlStatement"] ;
}
catch(Exception){}
finally{}


Use this logic but make sure to remove the Session at some point somewhere
in your logic.

Hope this helps,

Yama


NOTE:
You should never use sp_StoredProcedureName because the sp_ is queried
through master database.

Dan said:
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

}
}
 
D

Dan Poincelot

Hi Yama, thanks for the response. Unfortunately, I'm trying to avoid
using session variables. Do you know of any way to just make certain the
radio buttons function fires before the onbubbleevent? Thanks for the sp
tip too;)
 
D

Dan Poincelot

Hi Yama, do you mean load the radio buttons in the page_init and that
will make them fire first when clicked? If so, how do you load them
there?
Thanks for your help.
 
D

Dan Poincelot

Hi Yama, are you saying to load the radio buttons in the page_init and
that will make their function fire first, before the drop downs
onbubbleevent? If so, how do I do this?
Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top