G
Guest
I have a web form, which load a web control by using the LoadControl
method
void Page_Init(...)
{
Control ctl = LoadControl(Request.QueryString["module"]+".ascx"); //
url = default.aspx?module=control1
Panel1.Controls.Add(ctl);
}
Now, I want to add to the web form a DropDownList control, which
should interact with the web control.
void Page_Load(...)
{
DropDownList ddl = new DropDownList();
ddl.DataSource = ...
ddl.DataBind();
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(IndexChanged);
}
void IndexChanged(object sender, EventArgs e)
{
Session["MY_KEY"] = ((DropDownList)sender).SelectedItem.Value;
}
and now I want to use an actual value of the DropDownList (or a
session key) in the web control
void Page_Load()
{
Response.Write(Session["MY_KEY"]);
}
The problem is here that when the selected item in the DropDownList
has been changed, the sequence is following:
webform.init/load
webcontrol.load
webform.IndexChanged
And finally the rendered page shows the "old" Session["MY_KEY"]
because the IndexChanged has been executed after the contol is loaded.
So, how do I get the actual value of the DropDownList inside the web
control?
method
void Page_Init(...)
{
Control ctl = LoadControl(Request.QueryString["module"]+".ascx"); //
url = default.aspx?module=control1
Panel1.Controls.Add(ctl);
}
Now, I want to add to the web form a DropDownList control, which
should interact with the web control.
void Page_Load(...)
{
DropDownList ddl = new DropDownList();
ddl.DataSource = ...
ddl.DataBind();
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(IndexChanged);
}
void IndexChanged(object sender, EventArgs e)
{
Session["MY_KEY"] = ((DropDownList)sender).SelectedItem.Value;
}
and now I want to use an actual value of the DropDownList (or a
session key) in the web control
void Page_Load()
{
Response.Write(Session["MY_KEY"]);
}
The problem is here that when the selected item in the DropDownList
has been changed, the sequence is following:
webform.init/load
webcontrol.load
webform.IndexChanged
And finally the rendered page shows the "old" Session["MY_KEY"]
because the IndexChanged has been executed after the contol is loaded.
So, how do I get the actual value of the DropDownList inside the web
control?