Overview
ASP. NET pages usually contain commands that allow you to specify page attributes and configuration information for the corresponding pages. These commands are used by ASP. NET to process pages, but are not displayed as part of the Flag sent to the browser.
Main Types
Asp.net supports 11 types of commands.Brief Introduction, Commonly used three types, namely:
? @ Page, @ Import, @ Register
This section describes their functions and common attributes.
Introduction 1. @ Page
Function: Defines the page-specific (. aspx file) attributes used by ASP. NET page analyzer and compiler. This command allows you to specify multiple configuration options for the page, including:
? The server programming language of the Code in the page.
? Whether the server code is directly included in the page (called a single file page) or the code is included in a separate class file (called a code hidden page ).
? Debugging and tracing options.
? Whether the page has an associated master page, and whether it should be regarded as a content page accordingly.
Syntax:<% @ Page attribute = "value" [attribute = "value"...] %>
Main attributes:
1. Language: Specifies the Language used for compiling all inline rendering (<%> and <% = %>) and Code declaration blocks on the page. The value can represent any language supported by. NET Framework, including Visual Basic, C #, or JScript. Each page can only use and specify one language.
2. AutoEventWireup: indicates whether the page events are automatically bound. True if event auto binding is enabled; otherwise, false. The default value is true.
3. CodeFile: Specifies the path of the code hidden file pointing to the page reference. This property is used together with the Inherits (Code hiding class defined for page inheritance) property to associate the code hidden source file with the webpage. This attribute is only valid for compiled pages.
4. Debug: indicates whether the page should be compiled using debugging symbols. True if the page should be compiled with a debug symbol; otherwise false. Because this setting affects performance, this attribute should be set to true only during development.
5. Async: Make the page an asynchronous handler (that is, the page uses the IHttpAsyncHandler implementation to process requests ). The default value is false.
6. AsyncTimeOut: defines the timeout interval (in seconds) used to process asynchronous tasks ). The default value is 45 seconds. The value must be an integer.
Ii. @ Import
Purpose:Explicitly import the namespace to ASP.. NET application files (such as web pages, user controls, master pages, or Global. all the classes and interfaces of the imported namespace can be used in files.
Syntax:<% @ Import namespace = "value" %>
Attribute:Namespace: The namespace to be imported. This can include any namespace or custom namespace contained in. NET Framework.
Note:
? The @ Import command cannot have multiple namespace attributes. To Import multiple namespaces, use multiple @ Import commands.
? A group of namespaces can be automatically imported to the. aspx page. The imported namespace is defined in the computer-level Web. config file. The specific location is Element .
Iii. @ Register
Purpose:It provides developers with a simple method to reference custom controls in ASP. NET application files (including web pages, user controls, and master pages. Drag the user control to the. aspx page, and VS will create a @ Register command at the top of the page. In this way, the user control is registered on the page, and the control can be accessed through a specific name on the. aspx page.
Syntax:
? <% @ Register tagprefix = "tagprefix" namespace = "namespace" assembly = "assembly" %>
? <% @ Register tagprefix = "tagprefix" namespace = "namespace" %>
? <% @ Register tagprefix = "tagprefix" tagname = "tagname" src = "pathname" %>
Attribute:
Assembly: the Assembly associated with the TagPrefix, that is, the DLL
Namespace: Namespace associated with TagPrefix
Src: Location of the User Control
TagName: alias associated with the class name
TagPrefix: alias associated with the namespace
Example:
? When a TextBox is dragged to a Web page, the following code is added to the Web page:
? When a third-party control, such as IEWebControl, is dragged to a Web page, the following code is added to the Web page: <% @ RegisterTagPrefix = "iewc" Namespace = "Microsoft. web. UI. webControls "Assembly =" Microsoft. web. UI. webControls "%>
In the preceding HTML, "asp" is the TagPrefix of the server control.
Summary
? When using commands, although the standard practice is to include commands at the beginning of a file, they can be located anywhere in the. aspx or. ascx file. Each instruction can contain one or more attributes specific to the instruction (in pairs with values ).
? Recently, it is also necessary to simply understand these things. There are too many things to understand, and they are also eating at 1.1 o'clock.