views:

20

answers:

1

Say I have a web site with a master page and an aspx page.

In my ASPX page, I am pointing to my masterpage with the MasterType tag.

<%@ MasterType VirtualPath="~/mymasterpage.master" %>

Say, I've defined a label in the markup of my master page.

If you look at the designer code, this label should be something like this.

protected global::System.Web.UI.WebControls.Label label1;

Now in my content page, I would like to reference this label. If I type in this "Master.label1", the complier will complain that the control is inaccessible due to the protection level" and rightly so, as label1 is automatically defined as "protected".

My question is, if I define controls in my markup page, is it possible to set these controls as public instead of protected? I do not see an attribute for it.

thanks in advance.

+2  A: 

You can manually make them public by changing the designer code of course, but generally speaking this is incorrect design. They are protected for a reason, in that any class which is "aware" of your page, control or master class and interacts with it should interact with specialized properties and events which the class exposes, not the controls themselves.

Rex M