i loaded my user control (.ascx) programmatically like: LoadControl("~/Controls/mycontrol.ascx")
. Every thing was ok until today when i added two members to my control:
public StuffType stuffType { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
switch (stuffType)
{
cas开发者_开发知识库e CardType.A:
FillGvStuff();
break;
case CardType.B:
FillGvExStuff();
break;
default:
break;
}
}
how can i access StuffType?
i found a kind of solution.
I think you'd do something like this:
MyControl ctrl = (MyControl)LoadControl("~/Controls.mycontrol.ascx");
ctrl.stuffType = ...;
// put control somehwere
Basically, when you load it, assign it to a variable and cast it as its type and you should then have access to its methods and properties
You might also want to move your page_load event into page_prerender so that you are definetly setting the property before the page_load event occurs in the control
精彩评论