asp.net - I want to access controls of derive class from base class on onLoad() override in c# (Master page derive from one masterClass) -
i defined multiple master , has common functionality on form_load event. declare custommasterpage class derived system.web.ui.masterpage , put common functionality this. want override onpage_load() , want print controls of dervived class.
suppose have 1 custommaster class
class custommasterclass:system:web.ui.masterpage { override onload() { base(e) //i want use following child class controls(lblname) here print // lblname.text="" } } class child1:custommaster { //controls are.. //label:id=lblname; form_load() { lblname.text="test1 test1"; } } class child2:custommaster { //controls are.. //label:id=lblname; form_load() { lblname.text="test2 test2"; } }
how that. please give me advice
thanks in advance
base classes don't know child classes. being said, can define base class having overridable methods derived class can use set specific things, like:
public class baseclass { public override onload(object sender, eventargs e) { base.onload(e); setlabels(); //this call appropriate child class method } public virtual void setlabels() { } } public class childclass1 : baseclass { public override void setlabels() { //set label here } } public class childclass2 : baseclass { public override void setlabels() { //set label here } }
Comments
Post a Comment