Home >Backend Development >C#.Net Tutorial >Methods and techniques for parsing values passed in ASP.NET pages
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); }
b.aspx’s C# code
private void Page_Load(object sender, EventArgs e) { Label2.Text = Request.QueryString["name"]; }
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"); }
C# code in b.aspx. #
private void Page_Load(object sender, EventArgs e) { string name; Application.Lock(); name = Application["name"].ToString(); Application.UnLock(); }
private void Button1_Click(object sender, System.EventArgs e) { Session["name"] = Label.Text; }
private void Page_Load(object sender, EventArgs e) { string name; name = Session["name"].ToString(); }
4. Using
Cookie
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 private void Button1_Click(object sender, System.EventArgs e)
{
HttpCookie cookie_name = new HttpCookie("name");
cookie_name.Value = Label1.Text;
Reponse.AppendCookie(cookie_name);
Server.Transfer("b.aspx");
}
b.aspx. C# code
private void Page_Load(object sender, EventArgs e) { string name; name = Request.Cookie["name"].Value.ToString(); }
a.aspx C# code
public string Name { get{ return Label1.Text;} } private void Button1_Click(object sender, System.EventArgs e) { Server.Transfer("b.aspx"); }
b.aspx C# code
private void Page_Load(object sender, EventArgs e) { a newWeb; //实例a窗体 newWeb = (source)Context.Handler; string name; name = newWeb.Name; }
-->
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!