I'm having a problem dynamically loading controls. I have a page with a placeholder. There are 3 different controls ctl1, ctl2, ctl3 that I want to put in the placeholder (1 at a time, depending upon the value of a session variable called sessVar).
in ctl1 there is a submit button that when clicked it will change the value of sessVar. so i would like the corresponding control to load then.
here is the code to dynamically load the control:
switch (sessVar)
{
case 1:
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlFilters.ascx"));
break;
case 2:
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlResults.ascx"));
break;
case 3:
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlPropDetails.ascx"));
break;
default:
sm.sSearchStage = 1;
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlFilters.ascx"));
break;
}
the problem is that i cant figure out where to put the above code. if i put it in Page_Load() then the control is loaded before the click event in ctl1, so i have to refresh or click the button twice for ctl2 to load. if i put the above code in PreRender() then the button event does not even fire (which i don't understand).
i'm having the same problem as being mentioned here:
Thanks all,
Ryan
in ctl1 there is a submit button that when clicked it will change the value of sessVar. so i would like the corresponding control to load then.
here is the code to dynamically load the control:
switch (sessVar)
{
case 1:
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlFilters.ascx"));
break;
case 2:
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlResults.ascx"));
break;
case 3:
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlPropDetails.ascx"));
break;
default:
sm.sSearchStage = 1;
PlaceHolder1.Controls.Add(LoadControl("Controls/PropertySearch/ctlFilters.ascx"));
break;
}
the problem is that i cant figure out where to put the above code. if i put it in Page_Load() then the control is loaded before the click event in ctl1, so i have to refresh or click the button twice for ctl2 to load. if i put the above code in PreRender() then the button event does not even fire (which i don't understand).
i'm having the same problem as being mentioned here:
Thanks all,
Ryan