Reputation: 103
I need to pass a string value from the child.master to the parent.master. There is a function in parent.master
public void setMyString(string s)
{
myLiteral.Text = s;
}
How can I access such method from my child.master?
Upvotes: 1
Views: 228
Reputation: 13509
You have to cast the Child.master's Master to the Parent.master's class in order to call a method of that class.
Let's say the class name of the Parent.master is "ParentMasterPage". In Child.master, you can make a call like this:
((ParentMasterPage)this.Master).setMyString(param);
Upvotes: 2
Reputation: 2878
It's a good practice don't depend on the some Parent component at all, just image that in the future you decide to paste between child and parent master page some other master page - and you will have a trouble because of the reference to ex-parent master page.
So, in my opinion, it is better to define an event on childmaster page and have an event handler to this event on parent master page.
Upvotes: 0
Reputation: 732
If you simply want to call the parent function of the class, either don't overwrite it in the child class, or call the base method in the child function.
If you want to call the parent function of a specific instance of that parent class, then you'll need to have a reference to that instance in the child class instance.
Upvotes: 1