[ASP. NET Notes] 3. ASP. NET Running Model

Source: Internet
Author: User
1: page class
2: Asp.net controls
3: jump between pages and pass value
4: how to use a URL to query strings to pass Chinese Characters
5: Set the control to focus and set the default button of the webform form.

Page class
An Asp.net Application Program Every page in is inherited from the page class.
1) determine whether a page is loaded for the first time through ispostback
Whether text2.text = "3" is successfully loaded on the page
When I manually enter "4", I click the button again, but I still get "3"
If text2.text = "3" is not set during loading, the value is correct.
I don't know if it is textbox or button.
2) register the client JS through registerclientscriptblock
3) initialize data through the page_load event
4) How page events work:
There are two types of events in Asp.net. One is a client event, which is triggered by the client and processed by the client.
For example, onmoseover and onmouseout. Another event is a server-side event, which is caused by the page class
Generated. This kind of event is triggered by the client, but the client does not process it and is directly handled by the server.
For example, if a server event is triggered, the page will be submitted to the server. We call this process "Page return" later. Note that the return is from the client to the server.

5) page processing process:
A) when a page is returned, the client sends the control status (viewstate) of the current page to the server.
B) The server reloads the page. At this time, the page status is consistent with that at design time.
C) The server assigns the viewstate data status received from the client to the loaded page.
The status of the control on the page is the same as that of the control when the client is returned.
D) trigger the page page_load event
E) Handling of return events
F) The page is returned to the client.
Example:
1) define a variable, change the value in one button, and display the value in another button.
2) Add a Textbox Control and try again. Measure the test taker's knowledge about the role of viewstate.


Asp.net controls
Generally, Asp.net controls are divided into two types.
1: Web Control 2: HTML Control
Differences between Web controls and HTML controls
1) Web controls run on the server, while HTML controls run on the client.
2) Web controls run on the server side. After being parsed into HTML controls by IIS, they are displayed on the client side.
3) The web control label is <asp runat = "server">.
4) HTML controls can easily become Web controls [single right --> Run as server controls]
5) The reason why Asp.net contains HTML controls is to take care of the previous ASP
6) HTML controls are suitable for client programming, while Web controls are suitable for Server programming.
7) to reduce the server load, try to use HTML controls
8) If a web server control is added to a modal form, a new window is displayed each time the page is returned,
To avoid this problem, you can add <base target = "_ Self"/> between Example: think about using that type of controls
1) The user enters two numbers and sums them [using a text box]
2) Ask the user to enter some information and add it to the database [Use text box]

Page Jump

How to jump from a page to another page and transfer the value of the page
1) hyperlink control:
Feature: The Web control value cannot be passed, but the URL query string can be passed, which requires user control
Method: Set the navigateurl method. For example: 2. aspx? A = 4 & B = 5
Accept: request. querystring ["variable name"]
2) response. Redirect:
Feature: web control values cannot be passed, but URL query strings can be passed without user control
For example, jump from page a to page B, and then automatically jump from page B to Page C.
You can also use the URL query string to pass the control value. For example:
Response. Redirect ("2. aspx? XM = "+ this.txt user. Text );
Method: Response. Redirect ("target webpage? URL query string ").
For example: Response. Redirect ("2. aspx? A = 3 & B = 4 ")
Accept: request. querystring ["variable name"]
3) server. Transfer:
Feature: You can pass the web control value or URL query string without user control.
Method: Server. Transfer ("target webpage? URL query string ").
Accept: request. querystring ["variable name"] or request. Form ["txtuser"] value of the authorized control 4) published across the Web page:
Features: controls can be passed, and all attributes of controls can be passed, requiring user control and being more flexible.
Method: Specify the target webpage on the property "postbackurl. Generally, it is a button.
Tutorial: If (previouspage! = NULL) previouspage. findcontrol ("Control name ");
Example:
1) Source Page: select a department. All employees of the Department are displayed on the target page.
2) Source Page: Enter the user name and password. Check whether the user name and password are correct on the target page (without passing through the database)


How to use a URL to query strings to pass Chinese Characters
When passing Chinese characters through The RUL query string, it is sometimes found that the passed value does not match the received content or it turns into a pile of garbage codes. In this way, Chinese characters can be encoded before transmission. Then decode
Encoding: Server. urlencode ("Chinese character ")
Decoding: Server. urldecode ("Chinese character ")

Set the control to focus and set the default button of the webform form.
Declare in the <form> label
Syntax:
<Form defaultbutton = "button1" defaultfocus = "textbox1">

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.