"ASP." User Controls & Custom controls

Source: Internet
Author: User

In the original study, From VB to ASP. We are exposed to a lot of controls, these controls for our program development provides a lot of convenience, in the program development, many functions or code need to be repeated use, we in the beef brisket when we learned the template method and repeated code to add Toolbox call method, improve efficiency. Master pages are used in functionality, and user controls and custom controls are learned in ASP. Developers can develop their own user controls and custom controls to improve the reusability of the code. Here's a quick introduction to both of these controls.

One, user control:Definition:

A user control is a user-defined, reusable control that is represented by an. ascx file, which is not compiled code, and compiles dynamically with the Web page . Developers are able to define and write user controls based on the needs of the program, and the programming techniques used in development are the same as the techniques written in Web Forms, with a user interface page and a code-behind file that the developer modifies to make changes to all the controls that use the control's page. Create and use: Create a Web project, and right-click the project to add by tapping Web user control in Add. Then add the text and controls to the design surface for code writing. Drag directly onto the ASPX design surface when you use it.

differences from ASPX:

1. The extension must be. ascx.

2. <HTML>, <BODY> and <FORM> elements are not included in the user control

3. user controls cannot be run as pages alone and must be embedded in *.aspx pages or other user controls

To modify an ASPX page to a user control:

1. Removal of <HTML>, <BODY> and <FORM> elements

2. Change the ASP. NET instruction type from @page to. ascx in the Web Forms page

3. Change the base class from System.Web.UI.Page to System.Web.UI.UserControl

It is easier to modify, but the actual situation is generally not modified, directly to add.

Second, custom controls

Definition:

A Web custom control is a compiled component that runs on a server, encapsulating the user interface and other related functionality in a reusable package that contains all the design-time features of a standard ASP.

There are two types of custom server controls:The first type: *.aspx or *.cs code compiled after the production of the DLL, and then add the reference to the Toolbox for use, generally used in WebForm. The second type: *.cs implementation, compile DLL, add to toolbox used, generally used in WinForm.

Create and use:

Create a project right-click Add, ASP. NET server controls, such as in the way that we then rewrite the rendercontent function in code


iii. Comparison of user controls and custom controls


Iv. master Pages and user controls

1. master page extracts the peripheral public parts of multiple pages, when developing content pages, is embedded in the middle of the master page, and the user control is to extract multiple pages in the middle of any one of the public part, the development of the user control embedded in the development of the page, template page is a relatively simple way to save the consent style, Multiple pages on the same site if the style is inconsistent, it may have a bad effect, we can combine the common elements of a website (for example: website logo, navigation bar or ad bar) together as master page. The control can be a part of this, we can make the website logo, navigation bar into a separate control.

2. You can use a user control in a master page, and the master page cannot be used in a user control.

The current understanding of them is that both user controls and custom controls are intended for reuse and are a way for page reuse in ASP, which facilitates UI design. First understand the summary, if there are flaws please correct me.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"ASP." User Controls & Custom controls

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.