This article summarizes the method of passing values and parameters between C# pages. Share it for your reference. The specific implementation method is analyzed as follows:
1. QueryString value transmission
Generally speaking, QueryString is a very simple way to pass values. It can display the transmitted values in the browser's address bar. This method can be used if you pass one or more values with low security requirements or simple structure. However, this method cannot be used when passing arrays or objects. As shown in the following example:
{
string s_url;
s_url = "?name=" + ;
(s_url);
}
C# code:
{
= ["name"];
}
query value is also classified as post, get format
string name = Request["name"].toString();
string name =("name").toString();
//get request
string name = ["name"].toString();
But I found that whether it is post or get value transmission is available
The difference between get and post methods in form submission is summarized as follows:
1. Get is to get data from the server, and post is to transfer data to the server.
2. get adds the parameter data queue to the URL referred to by the ACTION attribute of the submitted form. The value corresponds to each field in the form one by one, and can be seen in the URL. Post is to pass the HTTP post mechanism to place each field in the form and its content in the HTML HEADER to the URL referred to by the ACTION attribute. Users cannot see this process.
3. For the get method, the server uses the value of the variable to get, and for the post method, the server uses the submitted data.
4. The amount of data transmitted by get is small and cannot be greater than 2KB. The amount of data transmitted by post is large and is generally defaulted to be unrestricted. But theoretically, the maximum amount in IIS4 is 80KB and 100KB in IIS5.
5. Get security is very low and post security is high.
2. Use Application object variables
The scope of the Application object is the entire global, which means it is valid for all users. The commonly used methods are Lock and UnLock.
C# code
{
Application["name"] = ;
("");
}
C# code
{
string name;
();
name = Application["name"].ToString();
();
}
3. Use Session variables
I believe this is definitely the most common usage in everyone's use. Its operation is similar to Application and acts on the user's personal, so excessive storage will lead to the exhaustion of server memory resources.
C# code
{
Session["name"] = ;
}
C# code
{
string name;
name = Session["name"].ToString();
}
4. Use cookie object variables
This is also a method that everyone often uses. Like Session, it is for every user, but there is an essential difference, that is, cookies are stored on the client side, while sessions are stored on the server side. Moreover, the use of cookies should be used in conjunction with the built-in object Request.
C# code
{
HttpCookie cookie_name = new HttpCookie("name");
cookie_name.Value = ;
(cookie_name);
("");
}
C# code
{
string name;
name = ["name"].();
}
5. How to use
This can be said to be the method used in the development of facial objects. Its usage guides the process from the current page to another page, and the new page uses the response flow of the previous page, so this method is completely facial objects, concise and effective.
C# code
{
get{ return ;}
}
private void Button1_Click(object sender, e)
{
("");
}
C# code
{
a newWeb; //Instance a form
newWeb = (source);
string name;
name = ;
}
I have summarized these items, but the one I use most is QueryString.
I hope this article will be helpful to everyone's C# programming.