Walaa,
I would like to comment your responses in this thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=11318&HighLight=1
in the Page_Load handler, don't add controls to the place holder, as follows:
Code:
if (Session["LoadPath"] != null)
{
Control control = LoadControl(Session["LoadPath"].ToString());
userControlPlaceHolder.Controls.Clear();
//userControlPlaceHolder.Controls.Add(control); // not needed
}
Just comment that line and everything will work just fine.
You must dynamically add the user control here because between post back the user control hierarchy does not save the dynamically created control. However what they should do here is use this routine in the OnInit instead of the Page_Load because OnInit is invoked before LoadViewState.
public partial class WebForm1 : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Session["LoadPath"] != null)
{
Control control = LoadControl(Session["LoadPath"].ToString());
uxPlaceHolder.Controls.Clear();
uxPlaceHolder.Controls.Add(control);
}
}
protected void uxBtn1_Click(object sender, EventArgs e)
{
string loadPath = "~/UserControls/WebUserControl1.ascx";
Session["LoadPath"] = loadPath;
}
protected void uxBtn2_Click(object sender, EventArgs e)
{
string loadPath = "~/UserControls/WebUserControl2.ascx";
Session["LoadPath"] = loadPath;
}
protected void uxBtn3_Click(object sender, EventArgs e)
{
uxLbl.Text = "Something else done";
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (Session["LoadPath"] != null)
{
Control control = LoadControl(Session["LoadPath"].ToString());
uxPlaceHolder.Controls.Clear();
uxPlaceHolder.Controls.Add(control);
}
}
}
I tried this but it does not work because when I have my uxBtn3_Click actually remove the control via uxPlaceHolder.Controls.Clear(). However before this function is invoked the OnInit was invoked and line uxPlaceHolder.Controls.Add(control); was executed!
I think the only way to do is to use the llblgenpro built that handles the error condition in llblgenprodatasource2:: OnPageLoadComplete .
BZ