Reputation: 504
I want to change master page some label value from child page.
Upvotes: 1
Views: 5103
Reputation: 5806
Create a property like this in master page:
public string MyText { get {return lbl.Text;} set {lbl.Text = value;}}
Once you do that you can use the same property in content page like:
((MasterPageTypeName)Page.Master ).MyText = "test";
and you are done!
Upvotes: 6
Reputation: 21
Everything is fine,just need to change:
((MasterPageTypeName)Page.MasterPage ).MyText = "test";
to ((MasterPageTypeName)Page.Master ).MyText = "test";
that's it,you are done.
Upvotes: 2
Reputation: 15762
Or you can just add '@mastertype' to the child page .aspx declaratively. This creates a strongly-typed reference to the masterpage.
<%@ MasterType VirtualPath="~/masters/SourcePage.master" %>
Upvotes: 1