Get the identifier of the homepage object on the content page

If there is a tag on the main page with the tag id1, how can I manage this identifier on the content page. The identifier is not transmitted, so I can not control it in essence. For example, if I have a control with the identifier contentLabel, I can access it just by typing contentLabel (whatever I do)

+6
source share
1 answer

Here are two options:

1 : make sure your aspx content points to MasterType :

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

This allows your content page to know what to expect from your main page, and gives you intellisense. So, now you can continue and set the Text property of the label on the main page of the code.

 public string ContentLabelText { get { return contentLabel.Text; } set { contentLabel.Text = value; } } 

Then you can access it on the page with the page code with the code ala:

 Master.ContentLabelText = "hah!"; 

or 2 . You can access the label through FindControl () like this:

 var contentLabel = Master.FindControl("contentLabel") as Label; 
+10
source

Source: https://habr.com/ru/post/918701/


All Articles