ASP.NET page pass-by-value object

      We all have this experience when we log in or register a website. If you log in to a certain website, it will be displayed on the website menu who is logged in. How is this effect achieved? This is mainly achieved by using page value transfer in ASP.NET.

First of all, we need to understand what client and server are:

The server serves the client, and the content of the service, such as providing resources to the client and saving the client data.

The client (Client), or the client, refers to the program corresponding to the server that provides local services for the client.

There are several large objects for passing values ​​on ASP.NET pages:

request object, get the requested object

The response object, the response is the response to the client.

The session object is used to save user information and can be applied to multiple pages to pass values.

A cook object that stores a small amount of information on the client side.

Application object

And we are more commonly used is the first three.

Hyperlink pass value:

Example: This is an index.aspx interface, and now it is necessary to pass 1 to the GoodsUpdate.aspx form.

<a href="GoodsUpdate.aspx?id=1">修改</a>

Receive and print at GoodsUpdate.aspx:

 response.write( request["id"]);

What if the value I want to pass is a database field change?

The following is the same example, but the specific value is changed to a field in the database.

<a href="GoodsUpdate.aspx?id=<%#Eval("TypeId") %>">修改</a>

The same is also request["id"] in the background reception in GoodsUpdate.aspx.

session pass value

Usually the website saves the user name with session to save, and uses session or request to receive your session information.

Usually written as:

session["name"]=your name.

Receive in the background and print it out:

response.write( request["name"]);

One advantage of session value transfer is that you can receive your stored session value anywhere, the foreground is also open, and the background is also available, which is more convenient to use. To receive in the foreground you need to use the session to receive the value you pass over, such as: <%=session["name"]%>. In the background, you can also use session to receive your session value. The receiving method is: response.write(session["name"]). Sometimes you need to typecast.

redirect redirect pass value

This method is usually used when we click the button to jump. His main function is to pass the value we want to a web page, and he mainly uses the session object to pass the value.

Use the session object to store the data you want to store. For example: session["any name"]=the value you want to pass, because the session can be received globally, there are two ways to pass the value. One is to bring the value in the webpage jump, such as: response.redirect('The address you want to jump to?='+session["Any name"]), in the background of the specified address, it is received as: session[ "Any name"]. The second is that you don't have to pass by value. Such as: response.redirect('the address you want to jump to'), the background reception is session["any name"].

  These are all my own understandings. I am not very good at learning skills. Maybe some places are ambiguous, which may cause you some trouble. I apologize here. In addition, please don't spray if you don't like it, after all, everyone is a novice.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325735248&siteId=291194637