Wednesday, March 28, 2012

Web Control Inheritence

I'm making a wizard where each page inherits some common properties. I'd like to make a WizardPage control (or class?) that has some other controls in it, and inherit it on each page of the wizard, so that I can access data members of each page by typecasting a control to WizardControl,a la


control ctlWizardStep = Page.LoadControl("Page1.ascx");
((WizardPage)ctlWizardStep).SomeProperty = "Smelly Chicken";

Is this possible?Yes, that should be possible. The only thing I see here is that you are using Page.LoadControl which loads up UserControls. So in order to do what you are asking, you would need to create the WizardPage and have that inherit from UserControl. Then on any other control, you would have that inherit from WizardPage and you should be able to do what you have listed above.

0 comments:

Post a Comment