There are 2 pages models of ASP.NET:
# 1, SINGLE-FILE-PAGE (single file web form page) Description: 1, you cannot create a single file web form page directly in Visual Studio. When you create a new page, Visual Studio creates a separate .aspx file and class file by default. To create a single file page, you must create it as a text file at the beginning and then change its extension to .aspx. 2. You cannot add non-visual components (such as data components) to this page by dragging from the toolbox because the web form designer does not hold these components in this page. Instead, this component should be added using the code. 3. Write code in the HTML view instead of the code editor. 4. When you write the code, IntelliSense will not be supported, you can't get the function of syntax checks or statements, terminate settings, or code format settings. 5. You must manually bind the event to the event handler. For single file web form pages, Visual Studio does not support the creation of a handler by double-clicking on the default event, nor supporting a drop-down list of categories and events in the code editor. 6. Some debugging functions are not supported, for example, it is not possible to view the variable by pointing the mouse to a variable value. 7. Since the code in this page is not compiled into a project assembly, it will not capture compile errors before running the page.
# 2, Codebehind (Code Post) Solution 2: Use CodeBehind and SRC Attributes (or Pre-Compilation and Auto Compilation) 1, <% @ Page CodeBehind = "Webform1.aspx.cs" inherits = "MyWeb.Webform1"% > CodeBehind just describes the inheritance class (MyWeb.Webform1) can be found in the webform1.aspx.cs file, just the designer (VS) tells the user a reference information, so does not execute at the page (Of course this statement is Didn't write it exactly). If it is not pre-compiled, an error occurs: ====== Analyzer error Description: An error occurred while analyzing the request to provide a service to this. Please check the following specific analysis error details and modify the source file appropriately.
Analyzer error message: Unable to load type "Test.webform1".
Source error:
1: <% @ page codebeHind = "Webform1.aspx.cs" inherits = "MyWeb.Webform1"%> ====== Solution: Compile the corresponding .aspx.cs file into the DLL into the bin folder Or use the SRC.
2, <% @ page src = "Webform1.aspx.cs" inherits = "myweb.webform1"%> src is very clear, explaining a code path, the page is automatically connected to the rear code, automatically compile.
According to everyone's own preferences and needs, as well as those in combination with maintainability, safety, etc., one of them is selected.