Sideway
output.to from Sideway
Draft for Information Only

Content

ASP.NET @ Webpage Directives
  @ Page Directive
   Syntax
   Attributes
  Attribute Values
  Remarks
  @ PreviousPageType
   Syntax
   Attributes
  Attribute Values
  Remarks
  @ Reference
   Syntax
   Attributes
  Remarks
 @ Register
   Syntax
   Attributes
  Remarks
  Source/Reference

ASP.NET @ Webpage Directives

The webpage directives for web form and user control are @ Assembly:, @ Control, @ Implements, @ Import, @ Master, @ MasterType, @ OutputCache, @ Page, @ PreviousPageType, @ Reference, and @ Register.

@ Page Directive

The @ Page directive is used to defines page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.

Syntax

<%@ Page attribute="value" [attribute="value"...] %>

Attributes

@ PageKeywords of @ Page directive attributeSpecified keywords from a list of attribute name used to specify attribute of @ Page attribute. "value"The specified value of the specified attribute of @ Page attribute.

Attribute Values

AsyncMakes the page an asynchronous handler (that is, it causes the page to use an implementation of IHttpAsyncHandler to process requests). The default is false. AsyncTimeOutDefines the time-out interval (in seconds) used when processing asynchronous tasks. The default is 45 seconds. The value must be an integer. AspCompatWhen set to true, allows the page to be executed on a single-threaded apartment (STA) thread. This allows the page to call STA components, such as a component developed with Microsoft Visual Basic 6.0. Setting this attribute to true also allows the page to call COM+ version 1.0 components that require access to unmanaged Active Server Pages (ASP) built-in objects. These are accessible through the ObjectContext object or the OnStartPage method. The default is false. Note: Setting this attribute to true can cause your page's performance to degrade. AutoEventWireupIndicates whether the page's events are autowired. true if event autowiring is enabled; otherwise, false. The default is true. BufferDetermines whether HTTP response buffering is enabled. true if page buffering is enabled; otherwise, false. The default is true. ClassNameA string that specifies the name of the page class that will be dynamically compiled when the page is requested. This value can be any valid class name and can include a fully qualified class name. If a value for this attribute is not specified, the class name for the compiled page is based on the page's file name and uses the default namespace ASP. If a value for the ClassName attribute is specified without a full namespace, then the namespace ASP is used, combined with the specified class name to create a fully qualified class name. Another page can reference the class name assigned to the first page by using the @ Reference directive. Note: It is possible in the code-behind page class to reference members of the associated .aspx page class using the fully qualified class name for the .aspx page. However, if you precompile your site with source protection enabled, the code-behind page class is not located in the same assembly as the .aspx page class. Therefore the class reference in the code-behind file will not work. ClientIDModeSpecifies the algorithm to use to generate ClientID values for controls. The default value is Predictable. The default value for controls is Inherit. Therefore, the default algorithm for controls in a page is determined by the ClientID setting of the page. A different default value can be set in the pages element of the Web.config file. ClientTargetIndicates the target user agent (typically, a Web browser such as Microsoft Internet Explorer) for which ASP.NET server controls should render content. This value can be any valid alias as defined within the <clientTarget> section of the application's configuration file. CodeBehindSpecifies the name of the compiled file that contains the class associated with the page. This attribute is not used at run time. This attribute is used for Web application projects. The CodeFile attribute is used for Web site projects. CodeFileSpecifies a path to the referenced code-behind file for the page. This attribute is used together with the Inherits attribute to associate a code-behind source file with a Web page. The attribute is valid only for compiled pages. This attribute is used for Web site projects. The CodeBehind attribute is used for Web application projects. CodeFileBaseClassSpecifies the type name of a base class for a page and its associated code-behind class. This attribute is optional, but when it is used the CodeFile attribute must also be present. Use this attribute when you want to implement a shared scenario, where you define common fields (and optionally, associated events) in a base class to reference the controls declared in a Web page. Because of the ASP.NET code generation model, if you defined the fields in a base class without using this attribute, at compile time new member definitions would be generated for the controls declared in the Web page (within a separate partial class stub), and your desired scenario would not work. But if you use the CodeFileBaseClass attribute to associate the base class with the page, and you make your partial class (its name is assigned to the Inherits attribute and its source file is referenced by the CodeFile attribute) inherit from the base class, then the fields in the base class will be able to reference the controls on the page after code generation. CodePageIndicates the value of the encoding scheme used for the response. The value is an integer that serves as an ID for the encoding scheme. CompilationModeSets whether the page should be compiled, using a string that specifies one of several enumerated options. The default value is Always, so .aspx pages are compiled by default. CompilerOptionsA string containing compiler options used to compile the page. In C# and Visual Basic, this is a sequence of compiler command-line switches. ContentTypeDefines the HTTP content type of the response as a standard MIME type. Supports any valid HTTP content-type string. CultureIndicates the culture setting for the page. The value of this attribute must be a valid culture ID. Note that the LCID and Culture attributes are mutually exclusive; if you use one of these attributes, you cannot use the other in the same page. DebugIndicates whether the page should be compiled with debug symbols. true if the page should be compiled with debug symbols; otherwise, false. Because this setting affects performance, you should only set the attribute to true during development. DescriptionProvides a text description of the page. This value is ignored by the ASP.NET parser. EnableEventValidationEnables validation of events in postback and callback scenarios. true if events are being validated; otherwise, false. The default is true. Page event validation reduces the risk of unauthorized postback requests and callbacks. When the enableEventValidation property is set to true, ASP.NET allows only the events that can be raised on the control during a postback request or callback. With this model, a control registers its events during rendering and then validates the events during the post-back or callback handling. All event-driven controls in ASP.NET use this feature by default. It is strongly recommended that you do not disable event validation. Before disabling event validation, you should be sure that no postback could be constructed that would have an unintended effect on your application. EnableSessionStateDefines session-state requirements for the page. true if session state is enabled; ReadOnly if session state can be read but not changed; otherwise, false. The default is true. These values are case-insensitive. EnableThemingIndicates whether themes are used on the page. true if themes are used; otherwise, false. The default is true. EnableViewStateSpecifies whether view state is maintained across page requests. This value is true if view state is maintained, or false if view state is not maintained. The default is true. Even if this property is set to true, view state will not be maintained for a control if any of the following conditions apply: The control's EnableViewState property is set to false. And the control's ViewStateMode property is set to Disabled or the control inherits the Disabled value. EnableViewStateMacIndicates that ASP.NET should verify message authentication codes (MAC) in the page's view state when the page is posted back from the client. true if view state should be MAC checked; otherwise, false. The default is true. A view-state MAC is an encrypted version of the hidden variable that a page's view state is persisted to when sent to the browser. The MAC is used to verify that view state has not been tampered with on the client. Security noteSecurity Note: This attribute should never be set to false in a production Web site. ErrorPageDefines a target URL for redirection if an unhandled page exception occurs. ExplicitDetermines whether the page is compiled using the Visual Basic Option Explicit mode. true indicates that the Visual Basic explicit compile option is enabled and that all variables must be declared using a Dim, Private, Public, or ReDim statement; otherwise, false. The default is false. Note: This attribute is ignored by languages other than Visual Basic. Also, this option is set to true in the Machine.config configuration file. InheritsDefines a code-behind class for the page to inherit. This can be any class derived from the Page class. This attribute is used with the CodeFile attribute, which contains the path to the source file for the code-behind class. The Inherits attribute is case-sensitive when using C# as the page language, and case-insensitive when using Visual Basic as the page language. If the Inherits attribute does not contain a namespace, ASP.NET checks whether the ClassName attribute contains a namespace. If so, ASP.NET attempts to load the class referenced in the Inherits attribute using the namespace of the ClassName attribute. (This assumes that the Inherits attribute and the ClassName attribute both use the same namespace.) LanguageSpecifies the language used when compiling all inline rendering (<% %> and <%= %>) and code declaration blocks within the page. Values can represent any .NET Framework-supported language, including Visual Basic, C#, or JScript. Only one language can be used and specified per page. LCIDDefines the locale identifier for the Web Forms page. Note: The locale identifier is a 32-bit value that uniquely defines a locale. ASP.NET uses the default locale of the Web server unless you specify a different locale for a Web Forms page by using this attribute. Note that the LCID and Culture attributes are mutually exclusive; if you use one of these attributes, you cannot use the other in the same page. LinePragmasDetermines whether the runtime should generate line pragmas in the source code. These are compiler options that are often used by debugging tools to mark specific locations in a source file. true if line pragmas should be generated; otherwise, false. MaintainScrollPositionOnPostbackIndicates whether to return the user to the same position in the client browser after postback. true if users should be returned to the same position; otherwise, false. The default is false. Note: Developers can define this attribute for all pages by setting the maintainScrollPostitionOnPostback attribute (note that it is case-sensitive in configuration files) on the <pages> element of the Web.config file. MasterPageFileSets the path to the master page for the content page or nested master page. Supports relative and absolute paths. MetaDescriptionSets the MetaDescription property. If the page markup also includes a "description" meta element, the value in the @ Page directive overrides the value in markup. MetaKeywordsSets the MetaKeywords property. If the page markup also includes a "keywords" meta element, the value in the @ Page directive overrides the value in markup. ResponseEncodingIndicates the name of the encoding scheme used for the HTTP response that contains a page's content. The value assigned to this attribute is a valid encoding name. for a list of possible encoding names, see the Encoding class. You can also call the GetEncodings method for a list of possible encoding names and IDs. SmartNavigationIndicates whether the page supports the smart navigation feature of Internet Explorer 5.5 or later. true if smart navigation is enabled; otherwise, false. The default is false. In ASP.NET version 2.0 and later versions, the SmartNavigation property is obsolete. Use the SetFocus method and the MaintainScrollPositionOnPostback() property instead. SrcSpecifies a path to a source file containing code that is linked to the page. In the linked source file, you can choose to include programming logic for your page either in a class or in code declaration blocks. You can use the Src attribute to link build providers to the page. For more information, see the BuildProvider class. Also, in versions of ASP.NET prior to 2.0, the Src attribute was used as an alternative way to link a code-behind file to a page. In ASP.NET 2.0, the preferred approach to linking a code-behind source file to a page is to use the Inherits attribute to specify a class, along with the CodeFile attribute to specify the path to the source file for the class. StrictIndicates that the page should be compiled using the Visual Basic Option Strict mode. true if Option Strict is enabled; otherwise, false. The default is false. Note: This attribute is ignored by languages other than Visual Basic. StyleSheetThemeSpecifies a valid theme identifier to use on the page. When the StyleSheetTheme attribute is set, individual controls can override the stylistic settings contained in a theme. Thus a theme can provide an overall look for a site, while the settings contained in the StyleSheetTheme attribute enable you to customize particular settings on a page and its individual controls. TargetSchemaSpecifies the name of a schema that validates content on the page. This serves only a descriptive purpose; no actual validation is performed, and the attribute is ignored by the parser. ThemeSpecifies a valid theme identifier to use on the page. When the Theme attribute is set without using the StyleSheetTheme attribute, it overrides individual style settings on controls, enabling you to create a unified and consistent look on a page. TitleSpecifies a title for the page that is rendered within the HTML <title> tags in the response. The title can also be accessed programmatically as a property of the page. For details, see the Title property. TraceIndicates whether tracing is enabled. true if tracing is enabled; otherwise, false. The default is false. TraceModeIndicates how trace messages are to be displayed for the page when tracing is enabled. Possible values are SortByTime and SortByCategory. The default, when tracing is enabled, is SortByTime. TransactionIndicates whether COM+ transactions are supported on the page. Possible values are Disabled, NotSupported, Supported, Required, and RequiresNew. The default is Disabled. UICultureSpecifies the user interface (UI) culture setting to use for the page. Supports any valid UI culture value. ValidateRequestIndicates whether request validation should occur. If true, request validation checks all input data against a hard-coded list of potentially dangerous values. If a match occurs, an HttpRequestValidationException exception is thrown. The default is true. This feature is enabled in the machine configuration file (Machine.config). You can disable it in your application configuration file (Web.config) or on the page by setting this attribute to false. Note: This functionality helps reduce the risk of cross-site scripting attacks for straightforward pages and ASP.NET applications. An application that does not properly validate user input can suffer from many types of malformed input attacks, including cross-site scripting and Microsoft SQL Server injection attacks. There is no substitute for carefully evaluating all forms of input in an application and making sure that they are either properly validated or encoded, or that the application is escaped prior to manipulating data or sending information back to the client. ViewStateEncryptionModeDetermines how view state is encrypted, with three possible enumerated values: Auto, Always, or Never. The default is Auto, meaning that view state will be encrypted if an individual control requests it. ViewStateModeSpecifies the ViewStateMode property value that will take effect for a control when the ViewStateMode property of the control is Inherit. The default ViewStateMode value for a page is Enabled. The ViewStateMode and EnableViewState properties determine whether view state is maintained for controls on a page. WarningLevelIndicates the compiler warning level at which you want the compiler to treat warnings as errors, thus aborting compilation of the page. Possible warning levels are 0 through 4.

Remarks

  • This directive can be used only in Web Forms pages. You can include only one @ Page directive per .aspx file.
  • Further, you can define only one Language attribute per @ Page directive, because only one language can be used per page.
  • Because the most commonly used default values are supplied for most of the attributes, either in the source code or in configuration files, it is often unnecessary to add a large set of attributes to the directive. Generally, you should add the minimal set of attributes required to specify the features you want for a page.
  • If there is a common attribute that you want to apply to all pages, for example if you want to enable tracing on all pages, consider enabling the feature in the Web.config file rather than adding the Trace attribute to every individual page.
  • Note: The @ Page directive has a number of attributes in common with other directives that apply to an entire source file, such as the @ Control directive (used in .ascx files for Web user controls) and the @ Master directive (used in .master files for master pages).
  • To define multiple attributes for the @ Page directive, separate each attribute/value pair with a single space. For a specific attribute, do not include a space on either side of the equal sign (=) that connects the attribute with its value. For an example, see the Example section of this topic.
  • Smart navigation is an ASP.NET feature supported in Internet Explorer 5.5 and later browsers. It allows a page to be refreshed while maintaining scroll position and element focus between navigations, causing only a single page to be stored in the browser's history, and without the common flicker associated with refreshing a Web page. Smart navigation is best used with ASP.NET pages that require frequent postbacks but with visual content that does not change dramatically on return. Consider this carefully when deciding whether to set this attribute to true.
  • When the AspCompat attribute is set to true for a page, if you use a constructor to create a COM component before the request is scheduled, it will run on a multithreaded apartment (MTA) thread. Doing this causes significant Web server performance degradation. To avoid this problem, create COM components only from within one of the Page events (such as Page_Load, Page_Init, and so on) or one of the Page methods. Be sure as well that the objects are not created at page construction time.
  • Note: Adding an @ Master directive to a master page does not allow you to use the same directive declaration in pages that depend on the master. Instead, use the pages element to define page directives globally.

@ PreviousPageType

The @ PreviousPageType directive is used to provides a way to get strong typing against the previous page, as accessed through the PreviousPage property.

Syntax

<%@ PreviousPageType attribute="value" [attribute="value"...] %>

Attributes

@ PreviousPageTypeKeywords of @ PreviousPageType directive attributeSpecified keywords from a list of attribute name used to specify attribute of @ PreviousPageType attribute. "value"The specified value of the specified attribute of @ PreviousPageType attribute.

Attribute Values

TypeNameSpecifies the type name for the previous page. VirtualPathSpecifies the path to the file that generates the strong type.

Remarks

  • Use the @ PreviousPageType directive to get strong typing against the PreviousPage property.
  • You can use the @ PreviousPageType directive only on a Web Forms page (an .aspx file).
  • If both attributes, TypeName and VirtualPath, are defined, the @ PreviousPageType directive will fail.

@ Reference

The @ Reference directive is used to indicates that another user control, page source file, or arbitrary file located at some virtual path should be dynamically compiled and linked against the current ASP.NET file (Web page, user control, or master page) in which this directive is declared.

Syntax

<%@ Reference Page="path to .aspx page" 
    Control="path to .ascx file" 
    virtualPath="path to file" %>

Attributes

@ ReferenceKeywords of @ Reference directive PageThe external page that ASP.NET should dynamically compile and link to the current file that contains the @ Reference directive. ControlThe external user control that ASP.NET should dynamically compile and link to the current file that contains the @ Reference directive. VirtualPathThe virtual path for the reference. Can be any file type as long as a build provider exists. For example, it would be possible to point to a master page.

Remarks

  • Using this directive allows you to dynamically compile a page, a user control, or another type of file that is associated with a build provider, and link it to the current Web page, user control, or master page file that contains the @ Reference directive. This allows you to reference the external compiled object and its public members from within the current file.

@ Register

Creates an association between a tag prefix and a custom control, which provides developers with a concise way to refer to custom controls in an ASP.NET application file (including Web pages, user controls, and master pages).

Syntax

<%@ Register tagprefix="tagprefix" 
    namespace="namespace" 
    assembly="assembly"  
%>
<%@ Register tagprefix="tagprefix"
   namespace="namespace" 
%>
<%@ Register tagprefix="tagprefix"
   tagname="tagname"
   src="pathname" 
%>

Attributes

@ RegisterKeywords of @ Register directive assemblyThe assembly in which the namespace associated with the tagprefix attribute resides. Note The assembly name cannot include a file extension. Also note that if the assembly attribute is missing, the ASP.NET parser assumes that there is source code in the App_Code folder of the application. If you have source code for a control that you want to register on a page without having to compile it, place the source code in the App_Code folder. ASP.NET dynamically compiles source files in the App_Code folder at run time. namespaceThe namespace of the custom control that is being registered. srcThe location (relative or absolute) of the declarative ASP.NET User Controls file to associate with the tagprefix:tagname pair. tagnameAn arbitrary alias to associate with a class. This attribute is only used for user controls. tagprefixAn arbitrary alias that provides a shorthand reference to the namespace of the markup being used in the file that contains the directive.

Remarks

  • Including the @ Register directive in a page or user control allows you to lay out custom server controls or user controls using declarative Custom Server Control Syntax.
  • Note: You can also register custom controls on all the pages of an application by using the controls Element for pages (ASP.NET Settings Schema) in the Web.config file.
  • Use the @ Register directive in the following situations:
    • To add a custom server control declaratively to a Web page, a user control, a master page, or a skin file (see ASP.NET Themes and Skins).
    • To add a user control declaratively to a Web page, a user control, a master page, or a skin file.
  • Note: The tagprefix value "mobile" is used by ASP.NET to identify the mobile Web controls in the System.Web.UI.MobileControls namespace. You should avoid using this prefix for your controls.
  • When you use the @ Register directive to reference a control, you can place the code for the control in the following places:
    • As source code in the application's App_Code folder, where it will be dynamically compiled at run time. This is a convenient option during development. If you choose this option, you do not use the assembly attribute in the @ Register directive.
    • As a compiled assembly in the application's Bin folder. This is a common option for deployed Web applications.
    • As a compiled and signed assembly in the global assembly cache (GAC). This is a common option if you want to share a compiled control among multiple applications. You can reference a control in the GAC by assigning an identifying string to the assembly attribute. The string specifies the required details about the control, including its fully qualified type name, its version, its public key token, and its culture.
  • For declarative user controls, use the tagname, tagprefix, and src attributes. The first two are always used together as a colon-separated pair (tagprefix:tagname) when you declare the control in the page. You can map multiple namespaces to the same tagname.
  • The src attribute value can be either a relative or an absolute path to the user control source file from your application's root directory. For ease of use, it is recommended you use a relative path. For example, assume you store all your application's user control files in a \Usercontrol directory that is a subdirectory of your application root.
  • The tilde (~) character represents the root directory of the application.
  • Note: If your user control is in the same directory as the page that contains it, the src attribute value should be the name and extension of the .ascx file.
  • When including custom server controls that you have compiled into a .dll file for use with your application, use the tagprefix attribute with the assembly and namespace attributes. If you do not include the namespace attribute, or if you assign an empty string ("") to it, a parser error will occur.
  • Caution: When you develop a custom server control, you must include it in a namespace. If you do not, it will not be accessible from an ASP.NET page.

Source/Reference

  • https://docs.microsoft.com/en-us/previous-versions/t8syafc7(v=vs.140)
  • https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ydy4x04a(v=vs.100)
  • https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms228169(v=vs.100)
  • https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/w70c655a(v=vs.100)
  • https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/c76dd5k1(v=vs.100)

©sideway

ID: 190600030 Last Updated: 6/30/2019 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019