H
Harry
Hello,
I have a page with a RadioButtonList and a PlaceHolder control. The
RadioButtonList's AutoPostBack attribute is set to TRUE and its
SelectedIndexChanged event loads one of three UserControls into the
PlaceHolder's child control collection depending upon which of the three
radio buttons is selected. Each of the three UserControls have postback
events themselves triggered by button clicks. The problem I'm having is
keeping track of what UserControl to load upon a page being posted back. My
SelectedIndexChanged event will load a UserControl dynamically just fine,
however, in the event that the dynamically loaded user control itself issues
a postback the parnets Page_Load event must remeber which UserControl to
reload so it can handle its postback. In order to do this, I store the
loaded control's name in the ViewState. This solution causes a problem in
that moveing from one dynamically loaded UserControl to another will cause
two controls to be displayed at the same time. To fix this my
SelectedIndexChanged event will remove the first child control in the
PlaceHolder. However, this solution totally screws with my postback such
that they do not fire porperly. Here is an example of what I'm doing:
private void Page_Load(object sender, System.EventArgs e)
{
if (ViewState["ControlName"] != null)
PlaceHolderControl.Controls.Add(LoadControl(ViewState["ControlName"].ToStrin
g()));
}
private void MyRadioButtonList_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if (PlaceHolderControl.HasControls())
PlaceHolderControl.Controls.RemoveAt(0);
ViewState["ControlName"] = MyRadioButtonList.SelectedValue;
PlaceHolderControl.Controls.Add(LoadControl(MyRadioButtonList.SelectedValue)
);
}
Any suggestions would be much appreciated.
- Harry
I have a page with a RadioButtonList and a PlaceHolder control. The
RadioButtonList's AutoPostBack attribute is set to TRUE and its
SelectedIndexChanged event loads one of three UserControls into the
PlaceHolder's child control collection depending upon which of the three
radio buttons is selected. Each of the three UserControls have postback
events themselves triggered by button clicks. The problem I'm having is
keeping track of what UserControl to load upon a page being posted back. My
SelectedIndexChanged event will load a UserControl dynamically just fine,
however, in the event that the dynamically loaded user control itself issues
a postback the parnets Page_Load event must remeber which UserControl to
reload so it can handle its postback. In order to do this, I store the
loaded control's name in the ViewState. This solution causes a problem in
that moveing from one dynamically loaded UserControl to another will cause
two controls to be displayed at the same time. To fix this my
SelectedIndexChanged event will remove the first child control in the
PlaceHolder. However, this solution totally screws with my postback such
that they do not fire porperly. Here is an example of what I'm doing:
private void Page_Load(object sender, System.EventArgs e)
{
if (ViewState["ControlName"] != null)
PlaceHolderControl.Controls.Add(LoadControl(ViewState["ControlName"].ToStrin
g()));
}
private void MyRadioButtonList_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if (PlaceHolderControl.HasControls())
PlaceHolderControl.Controls.RemoveAt(0);
ViewState["ControlName"] = MyRadioButtonList.SelectedValue;
PlaceHolderControl.Controls.Add(LoadControl(MyRadioButtonList.SelectedValue)
);
}
Any suggestions would be much appreciated.
- Harry