ASP. NET modification page inherits

Source: Internet
Author: User

<@ Page: Relationship between codebehind, inherits, and aspx

Codebehind specifies the name of the compiled file that contains the class associated with the page. This attribute cannot be used at runtime.

Note: This attribute is provided to achieve compatibility with ASP. NET of previous versions.CodeHide. In ASP. NET 2.0, you should use the codefile attribute to specify the name of the source file, and use the inherits attribute to specify the fully qualified name of the class.

Codefile specifies the path to the code hidden file referenced by the page. This property can be used together with the inherits property to associate the hidden source file of code with the webpage. This attribute is only valid for compiled pages.

Inherits

Defines the code hidden class for page inheritance. It 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 of the Code hiding class. The inherits attribute is case-sensitive when C # is used as the page language time zone, while Visual Basic is not case-sensitive when used as the page language.

If the inherits attribute does not contain a namespace, ASP. NET checks whether the classname attribute contains a namespace. If it contains, ASP. NET tries to use the namespace of the classname attribute to load the class referenced in the inherits attribute. (This assumes that the inherits and classname attributes use the same namespace .)

For more information about the code hiding class, see ASP. NET webpage code model.

Classname is a string that specifies the name of the page class that will be dynamically compiled during the request page. This value can be any valid class name and can include a fully qualified class name. If the value of this attribute is not specified, the Class Name of the compiled page will use the default namespace ASP Based on the page name. If the value of the specified classname attribute does not have a complete namespace, ASP is used together with the specified class name to create a fully qualified class name.

For other pages, you can use the @ reference command to reference the class name assigned to the first page.

Note: You can use the fully qualified class name on the. ASPX page to reference the members of the associated. ASPX page class in the code hidden page class. However, if pre-compilation is enabledSource codeThe hidden page class is different from the. ASPX page class.ProgramCentralized. Therefore, the classes referenced in the Code hiding file do not work. For more information about pre-compilation, see ASP. Net pre-compilation overview.

SRC specifies the path of the source file containing the Code that links to the page. In the source file of the link, you can choose to include the page programming logic in the class or the Code declaration block.

You can use the SRC property to link the generated provider to the page. For more information, see buildprovider class. In addition, in ASP. NET versions earlier than 2.0, the src attribute is another method to link a hidden code file to a page. In ASP. NET 2.0, the preferred way to link a hidden source file to a page is to use the inherits attribute to specify the class and use the codefile attribute to specify the path of the source file of the class.

View code

 Code highlighting produced by actipro codehighlighter (freeware) http:  //  Www.codehighlighter.com/--> the inherits attribute is namespace (Liuxiang) + class name (inheritclass). inheritclass must inherit page <% @ Page Language = "  C #  " Autoeventwireup = "  True  " Codebehind = "  Default. aspx. CS  " Inherits = "  Liuxiang. inheritclass  " %> <! Doctype HTML public "  -// W3C // dtd xhtml 1.0 transitional // en "   "  Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd  " > <HTML xmlns = "  Http://www.w3.org/1999/xhtml  " > <Head runat = "  Server  " > <Title>  "  Form1  " Runat = " Server  " > <Div> <asp: textbox id = "  Txtname  " Runat = "  Server  " > </ASP: textbox> <asp: Label id = "  Labname  " Runat = "  Server  " > </ASP: Label> <asp: button id ="  Btnname  " Runat = "  Server  " TEXT = "  OK  " Onclick = "  Button#click  " /> </Div> </form> </body>  The code in default. aspx. CS is <% @ Inherits in page points to the class inheritclass, so no controls on the page can be referenced in the code file. Using  System;  Using  System. Collections. Generic;  Using  System. LINQ;  Using  System. Web;  Using  System. Web. UI;  Using  System. Web. UI. webcontrols;  Namespace  Liuxiang {  Public   Partial  Class  _ Default: system. Web. UI. Page {  Protected   Void Page_load ( Object  Sender, eventargs e) {}} inheritclass code inherits from system. Web. UI. Page and can directly reference controls.  Using  System;  Using  System. Collections. Generic;  Using  System. LINQ;  Using  System. Web; Using  System. Web. UI. webcontrols;  Namespace  Liuxiang {  Public   Partial   Class  Inheritclass: system. Web. UI. Page {  //  Textbox txtname;  //  Label labname;  //  Button btnname;          Protected  Void Button#click ( Object  Sender, eventargs e) {labname. Text = This  . Txtname. Text ;}}} 

 

This method has the advantage of encapsulating all the code on the page into a class file, and then shelling the DLL to effectively protect the code.

However, this method can be executed in the Asp.net web application! However, if it is a Web site, this method does not seem to work.

ASPnet: Make sure that the class defined in this Code File matches the "inherits" attribute and that the base class (such as page or usercontrol) of this class extension is correct.

This error!

Hope that expert will advise ~~~~~

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.