Home > Backend Development > C#.Net Tutorial > Methods and techniques for parsing values ​​passed in ASP.NET pages

Methods and techniques for parsing values ​​passed in ASP.NET pages

怪我咯
Release: 2017-04-01 10:30:04
Original
1392 people have browsed it

1. Use QueryStringVariable

QueryString is a very simple value-passing method. It can display the transferred value in the browser. In the address bar. This method can be used when passing one or more values ​​with low security requirements or simple structure. However, this method cannot be used when passing arrays or objects. Here is an example:
a.aspx’s C# code

private void Button1_Click(object sender, System.EventArgs e)
{
    string s_url;
    s_url = "b.aspx?name=" + Label1.Text;
    Response.Redirect(s_url);
}
Copy after login

b.aspx’s C# code

private void Page_Load(object sender, EventArgs e)
{
    Label2.Text = Request.QueryString["name"];
}
Copy after login

2. Using the Application object variable
The scope of the Application object is the entire Global, that is to say, it is valid for all users. The commonly used methods are Lock and UnLock. C# code in
a.aspx

private void Button1_Click(object sender, System.EventArgs e)
{
    Application["name"] = Label1.Text;
    Server.Transfer("b.aspx");
}
Copy after login

C# code in b.aspx. #

private void Page_Load(object sender, EventArgs e)
{
    string name;
    Application.Lock();
    name = Application["name"].ToString();
    Application.UnLock();
}
Copy after login

3. Use

Session

Variables Presumably this is the most common usage among everyone. Its operation is similar to Application and affects the individual user. Therefore, excessive storage will cause Exhaustion of server memory resources. C# code in a.aspx

private void Button1_Click(object sender, System.EventArgs e)
{
    Session["name"] = Label.Text;
}
Copy after login

b.aspx

##
private void Page_Load(object sender, EventArgs e)
{
    string name;
    name = Session["name"].ToString();
}
Copy after login

4. Using
Cookie

Object variable

This is also a commonly used method. Like Session, it is for each user, but there is an essential difference, that is, Cookie is stored on the client, while Session is stored on the client. Server-side. And the use of cookies must be used in conjunction with the ASP.NET built-in object Request in the C# code

b.aspx. C# code

private void Page_Load(object sender, EventArgs e)
{
    string name;
    name = Request.Cookie["name"].Value.ToString();
}
Copy after login

5. Use the Server.Transfer method

This can be said to be the method used in object-oriented development. It uses the Server.Transfer method to guide the process from the current page to another In a page, the new page uses the response stream of the previous page, so this method is completely object-oriented, simple and effective.

a.aspx C# code

public string Name
{
    get{ return Label1.Text;}
}
private void Button1_Click(object sender, System.EventArgs e)
{
    Server.Transfer("b.aspx");
}
Copy after login

b.aspx C# code

private void Page_Load(object sender, EventArgs e)
{
    a newWeb;   //实例a窗体
    newWeb = (source)Context.Handler;
    string name;
    name = newWeb.Name;
}
Copy after login


-->

The above is the detailed content of Methods and techniques for parsing values ​​passed in ASP.NET pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template