ASP. NET learning notes (17)-page class details and application objects

Source: Internet
Author: User
Tags ftp site

1. The configigurationmanager class can access all the configuration information in the web. config file, for example:
Constr = configigurationmanager. connectionstrings ["constr"]. connectionstring;
2. When you use sqlcommand to set database operation commands, if the parameters in the SQL statement are as follows:
Sqlcommand insertcommand = new sqlcommand ("insert into table_a (C1, C2) values (@ P1, @ P2)", Conn );
Insertcommand. Parameters. Add ("parameter_id", sqldbtype.int, 4). value = userid. text;
Insertcommand. Parameters. Add ("parameter_name", sqldbtype. varchar, 50). value = username. text;
3. Obtain the date selected by the calendar control:
Date workdate = calendar. selecteddate
4. Data Template
<% # Expression %> is used to bind parameters to specific controls in the template. The placeholder expression can be eval ("column_name ") or bind ("column_name"), which can insert data into the attributes of several controls.
When you bind data to a control using <% # expression %>, the expression should contain the name of the data provider, such as DS. table ["user"]. eval ("userid ").
//////////////////////////////////////// ////////////////////////////////

1. Create a web site
Visual Studio can create a web site in the following locations:
1) on the local IIS Web Server (using the IIS Service)
2) Local disk (using built-in Web Services)
3) FTP site
4) remote Web servers supporting Front Page Server Extensions
The latter two use remote servers. The first method is the closest to the deployment environment, and the second method is convenient for testing, but there are the following restrictions:
1) only local computers can access the site
2) access to the SMTP service is restricted
3) The security mode is different from that of IIS: Application Program Run under the current user's account, rather than under a specific ASP. NET account
2. ASP. NET page description
1) MARK [Div]... [/Div:
2), runat attribute: indicates where the object will be processed, for example, runat = "server"
3) [@ % PAGE %] MARK: Define Page Features
Language: defines the page development language. The default value is VB. NET (the [script] Mark is the same). You can modify this attribute in Web. config.
Autoeventwireup, codefile, and inherits attributes are associated with the background Code In a partial category. This is generally the filename_aspx class. When autoeventwireup = false, you must manually link the page_load event.
3. ASP. NET code model:
In ASP. net includes HTML code (layout code), Asp. net Control and C # code, the first two are placed in. in the aspx file, C # code can be placed in. in the aspx file, it can also be stored in the background code file. CS file,
4. ASP. NET Server controls
ASP. NET pages can contain three types of controls:
1) HTML server controls,
2) Web server controls,
3) custom controls and user controls.
Web server controls appear in the layout code as XML elements, such as: [Asp: controlname runat = "server" attribute = "value"] Contents [/ASP: controlname]
Link the event handler in the operation code to the method on the control. For example, click the event in the button: add the attribute onclick = "btok_click"
5. When to use server controls:
When formatting the display layout, use the HTML control to Improve the Performance. When you need to dynamically display the UI, use the Web Server Control.
//////////////////////////////////////// ////////////////////////////////

Page details
1. Introduction to common page members:
1) attributes:
Application obtains the httpapplicationstate object for the current Web request.
Controls
Enableviewstate gets or sets a value that indicates whether the page maintains its view State and the view State of any server controls it contains at the end of the current page request.
Id.
Ispostback gets a value indicating whether the page is being loaded in response to the client's sending back, or whether it is being loaded and accessed for the first time.
The master node obtains the master page that determines the overall appearance of the page.
Request to obtain the httprequest object of the request page.
Response gets the httpresponse object associated with the page object. This object allows you to send HTTP response data to the client and contain information about the response.
Server obtains the server object, which is an instance of the httpserverutility class.
Session to obtain the current session object provided by ASP. NET
Theme gets or sets the topic name.
Title: obtains or sets the title of a page.
The user obtains information about the user who sends a page request.
2) Events:
Databind binds the data source to the called Server Control and all its child controls.
Dispose allows the Server Control to perform the final cleanup operation before being released from the memory.
Findcontrol searches for the specified server control in the page naming container.
Loadcontrol load control
Mappath retrieves the physical path mapped to the virtual path (absolute or relative) or application-related path.
Validate indicates all verification controls on the page to verify the information assigned to them
2. Page lifecycle and related events
Request page-> Start-> initialization page-> load page-> verify-> send back event processing-> display page-> uninstall
Preinit-> init-> initcomplete-> preload-> load-> loadcomplete-> prerender-> prerendercomplete->...-> unload-> disposed

//////////////////////////////////////// ////////////////////////////////

Application object:
The object's life cycle begins when the application starts running and closes the program. This allows for application-level data sharing (Session-level data sharing)
Application. Add ("key", "value"): Add a record to the Application Object and obtain the data: application. Contents ["key"]
Global Application class: Global. ascx
Global. ascx is closely related to the application object. It mainly sets Program-level variables and implements the onstart and onend events of the application.
You can usually put some database connection strings and system configuration parameters in this file.

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.