set a value of literal in web user control referenced by master page and master page is referenced by WebPage
Posted on 2007-07-19
I have this set up
Master Page references Web User control, in Web User control there is a Literal
WebPage.aspx references Master Page. I would like to set a value of Literal in Web User Control in WebPage.aspx.cs file. I can do this in two ways and I would like to find out if there is a better approach.
I use Master Type to create a reference to Master Page in WebPage.aspx and in WebPage.aspx.cs file I use Master.FindControl("Literal").Text = value etc ... The problem with this approach is FindControl, if in master page Web User Control is sitting inside of server elements than it would be a hard to reference it, and I would have to do it recursively.
I can create a public property in Master Page Code behind which will reference a Literal from Web user control and in WebPage.aspx.cs I access the property and set a value of a Literal through a property.
Which Approach is Better and is there another approach where I can avoid creating a property?