AjmeraInfo
AjmeraInfo

Reputation: 504

How to change master page value from child page

I want to change master page some label value from child page.

Upvotes: 1

Views: 5103

Answers (3)

Prashant Lakhlani
Prashant Lakhlani

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

Avishek
Avishek

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

SoftwareGeek
SoftwareGeek

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

Related Questions