asp.net page master page and ascx user Control transfer value problem _ practical Tips

Source: Internet
Author: User
Problem with ASPX page and ascx user control passing values
1. Create an ascx control
2. Add attributes to ascx
3. Drag the control into the ASPX
4. Accessing properties by control ID in the code in ASPX
such as: <uc3:left_repassword id= "Left_repassword1" runat= "Server"/>
Left_repassword1.highlight = value;
Also applies to master page access ascx

Asp. NET Access Master page (MasterPage) controls, properties, methods, and methods of calling content pages in master pages
Summarizes the ways in which ASP.net accesses master page (Master) controls, properties, methods, and call content pages (aspx) in master pages for your reference:

First, the master page must be strongly typed through the Mastertye directive in the content page, that is, add the following directive to the settings of the content page dock
<%@ MasterType virtualpath= "~/master/menuelement.master"%>
Where virtualpath sets the master page URL address.

1. Get the master page control reference.
Sample code
Copy Code code as follows:

<summary>
Get a reference to a TreeView control in a master page
</summary>
Public TreeView Elementstructuretree
{
Get
{
return tvelementstructure;
}
Set
{
Tvelementstructure = value;
}
}

As shown in the code above, define a public property elementstructuretree in the master page that references the Tvelementstructure control in the master page, and then In the content page, you can refer to the Tvelementstructure control in the master page through public property master (a property of the core object page) as follows:
TreeView TV = Master.elementstructuretree;
2. Access the master Page properties.
There are generally three types of properties in a master page: value type, class type, control type, and the "Get Master Page Control reference" above actually accesses the control type property, and the other two types of properties can be accessed in the same way.
3. Invoke the master page method.
The public methods defined in the master page can be called directly from Master.
4. The method that invokes the content page in the master page.
To define a delegate in a master page:
public delegate void Elementselectedchangehandler ();
Instantiate a delegate (another property) in a master page:
Public Elementselectedchangehandler Elementselectedchange {private get; set;}
Call the delegate where you want it in the master page:
Copy Code code as follows:

if (Elementselectedchange!= null)
{
Elementselectedchange ();
}

Specify a method in the content page that matches the delegate signature:
Master.elementselectedchange = this. Elementselectedchange;
The AutoEventWireup property of the 5.Master page must be set to "true" to automatically trigger all events for the control on the master page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.