ASPX page, master page and ascx User Control

Source: Internet
Author: User
Tags access properties
ASPX page and ascx User Control

1. Create an ascx Control

2. Add attributes to ascx

3. Drag the control into Aspx.

4. In the aspxCodeAccess properties by Control ID

For example, <uc3: left_repassword id = "left_repassword1" runat ="Server"/>

Left_repassword1.highlight = value;

It also applies to accessing ascx on the master page.

-----------------------------------------------------------------------

ASP . Net access the masterpage controls, properties, methods, and methods of calling the content page on the master page

The methods used to access the master page (master) controls, properties, methods, and calling the content page (aspx) in ASP. NET are summarized 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.

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.