ASP. Net access master page controls, attributes, methods, and masters

Source: Internet
Author: User

Today, I encountered A problem when I was working on the project, that is, there was A table in the parent board page and three classes A, B, and C were called.

But on the new page, I don't want these three classes. By accessing the Parent Board page attributes

This effect


First, you must use the MasterTye command on the Content Page to implement a strongly typed master page, that is, add the following command in the settings of the Content Page code Header
<% @ MasterType VirtualPath = "~ /Master/MenuElement. master "%>

VirtualPath sets the URL address of the master page.

The dashboard page defines the following attributes:
 

Reference the dashboard page for the following calls:

Master. LightBlueBg = "";

In this way, the three classes called on the motherboard page are successfully canceled ..

Summary:

This section summarizes ASP. Net's access to the master page controls, attributes, methods, and methods for calling content pages on the master page. For your reference:

First, you must use the MasterTye command on the Content Page to implement a strongly typed master page, that is, add the following command in the settings of the Content Page code Header

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

VirtualPath sets the URL address of the master page.

1. Obtain the control reference on the master page.

Sample Code

/// <Summary>

/// Obtain a reference to a TreeView control on the dashboard page

/// </Summary>

Public TreeView ElementStructureTree

{

Get

{

Return tvElementStructure;

}

Set

{

TvElementStructure = value;

}

}

As shown in the code above, a public attribute ElementStructureTree is defined on the master page, which references the tvElementStructure control on the master page, then, on the content Page, you can reference the tvElementStructure control in the Master Page by using the public attribute Master (an attribute of the core object Page), as follows:

TreeView TV = Master. ElementStructureTree;

2. Access master page properties.

There are generally three types of attributes on the master page: value type, class type, and control type. The above "Get Master Page Control Reference" is actually an access control type attribute, the other two types of attributes can be accessed in the same way.

3. Call the master PAGE method.

The public methods defined on the Master page can be directly called by the Master.

4. Call the Content Page Method on the master page.

Define delegation on the master page:

Public delegate void ElementSelectedChangeHandler ();

Instantiate the delegate in the master page (it is also an attribute ):

Public ElementSelectedChangeHandler ElementSelectedChange {private get; set ;}

Call the delegate as needed on the master page:

If (ElementSelectedChange! = Null)

{

ElementSelectedChange ();

}

On the content page, specify a method that matches the delegate signature:

Master. ElementSelectedChange = this. ElementSelectedChange;

5. The AutoEventWireup attribute of the Master page must be set to "true" to automatically trigger all events of the control on the Master page.

Today, I suddenly encountered a problem: how to obtain the sub-controls in the custom controls!

I went to Google .. Hey, I found the result .. Record it!

    

The page code is as follows:

          

Panel Login = (Panel) this. RightCommen1.FindControl ("PanelLogin ");
Panel PanelHot = (Panel) this. RightCommen1.FindControl ("PanelHot ");
Panel PanelSchool = (Panel) this. RightCommen1.FindControl ("PanelSchool ");
Panel PanelTea = (Panel) this. RightCommen1.FindControl ("PanelTea ");
Panel PanelHuiSuo = (Panel) this. RightCommen1.FindControl ("PanelHuiSuo ");
Panel PanelEnd = (Panel) this. RightCommen1.FindControl ("PanelEnd ");

PanelSchool. Visible = true;
PanelHuiSuo. Visible = false;
PanelEnd. Visible = false;

Hey, solve the problem through FindControl! But pay attention to the transformation problem!

 

Related Article

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.