Can I create controls defined in my markup instead of protected ones

Let's say I have a website with a master page and an aspx page.

In my ASPX page, I point to my master page with a MasterType tag.

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

      

Let's say I have defined a label in my main page markup.

If you look at the designer's code, this shortcut should be something like this.

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

      

Now in my content page, I would like to link to this shortcut. If I type this "Master.label1", then the complier will complain that the control is not available due to the protection level "and correctly, since label1 is automatically detected as" protected ".

My question is, if I define controls in my markup page, can I set those controls as public and not protected? I don't see an attribute for it.

early.

+2


a source to share


1 answer


You can make them public by changing the designer's code, but generally speaking, this is not a good design. They are protected for some reason, because any class that is "aware" of your page, controls, or interacts with a master class must interact with the specialized properties and events that the class provides, not the controls themselves.



+2


a source







All Articles