ASP. NET System Object and status management

Source: Internet
Author: User

1. Common System Objects in ASP. NET (also known as implicit objects or built-in objects ):

 

(1 .)PageObject: pointing to page itself Can be used during the execution of the entire page.

 

<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default "   %>

 

 

Language: Specifies the pageCodeAnd the language used by the post code;

Autoeventwireup: sets whether a page automatically calls a webpage event. Load events are called during page loading;

Codefile: the code file name stores the post-code. The post-code has a local relationship with the page.

Inherits: The page class specified in the red section of the following code for the page class. The two are one-to-one correspondence:

 

Public   Partial   Class   _ Default : System. Web. UI. Page
{
Protected   Void Page_load ( Object Sender, eventargs E)
{

}
}

 

 

(2.) RequestObject: Request data from a browser (client) Used for the page request period.

 

Querystring '? 'Post-Data

Form: Collects the request data sent by the POST method.

Servervariable: This set contains the system information of the server and client.

Params: Set of the above three types, not applicable.

 

(3.) ResponseObject:Provide information or instructions to the browser Used for the page execution period.

 

Write (): output the specified text

End (): Stop the current Web ServerProgramAnd return results

Redirect (): redirects to other pages

 

(4) ServerObject: Provides some server attributes and methods, such as the absolute path of the page file.

 

Mappath:

Server. mappath (string path) // path is the virtual path on the Web server and returns the physical path

Execute: Execute the page specified by parameters on the current page.

Transfer: Execute the page specified by parameters on the current page. After the execution of the specified page is completed, it does not return to the original page.

 

(5.) ApplicationObjects: share information with all users. It acts on the runtime of the entire application.

 

Application ["name"] = value;

Variable = application ["name"];

 

(6.) sessionObject: provide shared information for a user Act on the session period.

 

The session is also a set and can also be accessed using the indexer.

Session ["session name"] = value;

Variable = session ["session name"];

Session features:

The Session object contains the status information of a user (such as the logon Status). This information is not shared with other users and is only connected to this user.

The session timeout or expiration server immediately clears the resources occupied by the session object. Note: The server resources occupied by the session

Session status information is transmitted through sessionid during the session period. Unlike the cookie, all content is transmitted. The client is only visible to the sessionid, but not to the status information.

 

Common attributes and methods:

Sessionid: contains a unique user session identifier used to record user information throughout the session.

Timeout attribute: sets the session timeout in minutes.

Isnewsession attribute: returns true if the session has been created according to the current request.

Clear () method: Clear all keys and values from the session set

Abandon () method: ends the session and cancels the current session.

 

(7.) CookieObject: the shared information of the client.

Cookie is a collection object and accessed using the Indexer

Syntax:

Response Cookies [cookie name]. value = variable value; // write

String variable name = request. Cookies ["Cookie name"]. value; // read

Or

Httpcookie = new httpcookie ("Cookie name", "value ");

Response. Cookies. Add (cookie );

 

Common cookie attributes:

Name: Cookie variable name

Value: cookie value

Expire: Cookie Validity Period

The default cookie size is 4 kb.

 

2. Page pass value:

 

Prepare the first page default. aspx:

Target. aspx

Code

< Form ID = " Form1 " Runat = " Server " >
< Div >
< ASP: textbox ID = " Textbox1 " Runat = " Server " > </ ASP: textbox > & Nbsp;
< ASP: button ID = " Button1 " Runat = " Server " Text = " Button " Postbackurl = " ~ /Target. aspx " /> </ Div >
</ Form >

 

Page code:

Code

  Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
This . Textbox1.text =   " This is the first data to be loaded. " ;
}
If (Page. iscrosspagepostback) // Are you sure you want to use cross-Page Submission
{
This . Textbox1.text =   " Start cross-page Data Transmission " ;
}
}

 

Prepare target. aspx to place a label on the target page. The Code is as follows:

 

Code

If (Page. previouspage ! =   Null ) // Determine whether the transferred page exists
{
If (Previouspage. iscrosspagepostback)
{
Label1.text =   " Transmitted value: "   + (Textbox) This . Previouspage. findcontrol ( " Textbox1 " ). Text; // Locate the Textbox Control in the transferred page and obtain its value
}
}
Else  
{
Response. Redirect ( " Default. aspx " );
}

 

 

 

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.