Create a new class to act as the base control:
Then update your user controls to inherit from your base class instead of UserControl:
public partial class SampleControl2 : MyBaseControl
{
....
Then, in the place where you load the controls, change this:
To:
MyBaseControl uc = (MyBaseControl)LoadControl(controlPath);
uc.MyProperty = "foo";
PlaceHolder1.Controls.Add(uc);
Any suggestions will be appreciated greatly. !!.
public class MyBaseControl : System.Web.UI.UserControl
{
public string MyProperty
{
get { return ViewState["MyProp"] as string; }
set { ViewState["MyProp"] = value; }
}
}
{
public string MyProperty
{
get { return ViewState["MyProp"] as string; }
set { ViewState["MyProp"] = value; }
}
}
Then update your user controls to inherit from your base class instead of UserControl:
public partial class SampleControl2 : MyBaseControl
{
....
Then, in the place where you load the controls, change this:
UserControl uc = (UserControl)LoadControl(controlPath);
PlaceHolder1.Controls.Add(uc);
PlaceHolder1.Controls.Add(uc);
To:
MyBaseControl uc = (MyBaseControl)LoadControl(controlPath);
uc.MyProperty = "foo";
PlaceHolder1.Controls.Add(uc);
Any suggestions will be appreciated greatly. !!.
0 comments:
Post a Comment