asp.net page master page and ascx user control transfer problem

  • 2020-05-09 18:21:59
  • OfStack

aspx page with ascx user control value transfer problem
1. Create the ascx control
2. Attribute ascx
3. Drag the control into aspx
4. In the code of aspx, access the property by the control ID
Such as: < uc3:left_Repassword ID="left_Repassword1" runat="server" / >
left_Repassword1.HighLight = value;
The same applies to master page access to ascx

ASP.Net accesses master page (MasterPage) controls, properties, methods, and methods that invoke content pages from master pages
1. ASP.Net access master page (master) control, properties, methods and master page (aspx) call content page (aspx) method, for your reference:

First, the master page must be strongly typed through the MasterTye instruction in the content page, that is, the following instruction must be added in the setting of the content page generation terminal
< %@ MasterType VirtualPath="~/Master/MenuElement.master" % >
Where VirtualPath sets the master page URL address.

1. Get the master page control reference.
The sample code
 
/// <summary> 
///  Gets on the motherboard page 1 a TreeView Control reference  
/// </summary> 
public TreeView ElementStructureTree 
{ 
get 
{ 
return tvElementStructure; 
} 
set 
{ 
tvElementStructure = value; 
} 
} 

As shown in the above code, define a public property ElementStructureTree in the master page, which refers to the tvElementStructure control in the master page, and then refer to the tvElementStructure control in the master page through the public property Master (a property of the core object Page) in the content page, as follows:
TreeView tv = Master.ElementStructureTree;
2. Access master page properties.
There are three types of properties in master page 1: value type, class type and control type. The "get master page control reference" above is actually to access the control type property. The other two types of properties can be accessed in the same way.
3. Call the master page method.
The public methods defined in the master page can be called directly from Master.
4. Call the method of content page in master page.
Define the delegate in master page:
public delegate void ElementSelectedChangeHandler();
Instantiate the delegate in the master page (again, 1 property) :
public ElementSelectedChangeHandler ElementSelectedChange { private get; set; }
Invoke the delegate where needed in the master page:
 
if (ElementSelectedChange != null) 
{ 
ElementSelectedChange(); 
} 

Specify a method to match the delegate signature in the content page:
Master.ElementSelectedChange = this.ElementSelectedChange;
5. The AutoEventWireup property 1 on the Master page must be set to "true" to automatically trigger all events in the controls on the Master page.

Related articles: