I have many aspx pages which inherits a base Class.
base class has a method name “GetGroupID”, This method returns different data depends which page i am on, now few pages need to override this method (which is fine).
Problem:
I have user control which is placed in almost all pages, now this user control Accessess GetGroupID method from page base class, which is fine as long as i know page class name, since I have so many pages, one base class and one user control…it would be niceif I can get Page Class name from UserControl and execute the base method dynamically.
Curreny I have following code which works within UserControl
Dim c As homepage = CType(Me.Page, homepage)
Call c.getGroupID
However in above example I know the Page Class name (homepage), but lets say i am on a different page which has a classname “portal”, it would be impossible for me to keep track of so many pages.
I would like to excute the method in base class within user control, and I would like to override this method for certain pages.
please advise.
You could let the base-page implement a custom
interface, for exampleIGroupablewith a methodGetgroupId. Then you only have to know in theUserControlthat it’sPageisIGroupable(either directly or through inheritance) and you know for sure that it has a methodGetgroupId.You get the id in the
UserControlin this way: