For passing variables content between pages
ASP.NET gives us several choices. One choice is using Query String property
of Request Object
Page_load:
Advantages of this approach:
Implementing Query String:
Private void btnSubmit_Click (object sender,
System.EventArgs e)
{
Response.Redirect ("Webform2.aspx?Name=" +
this.txtName.Text + "&LastName=" +
this.txtLastName.Text);
}
Our first code part builds a query string for your
application and sends contents of your textboxes to second page. Now how to
retrieve these values from second page. Put this code to second page
Private void Page_Load(object sender,
System.EventArgs e)
{
this.txtBox1.Text = Request.QueryString ["Name"];
this.txtBox2.Text = Request.QueryString ["LastName"];
}
Request.QueryString is used to retrieve these
values
private void Page_Load(object sender, System.EventArgs
e)
{
this.txtBox1.Text = Request.QueryString[0];
this.txtBox2.Text = Request.QueryString[1];
}
Advantages of this approach:
- It is very easy.
Disadvantages of this approach:
- Query String have a max length, If you have to send a lot information this approach does not work.
- Query String is visible in your address part of your browser so you should not use it with sensitive information.
- Query String cannot be used to send & and space characters.
No comments:
Post a Comment