pass values from one page to another using query string in asp.net
Many times we want to pass values between asp.net pages. This can be easily done using Query String.
Let’s take an example where we will pass name & city of the person to page myWebpage.aspx using query string.
Let’s say we have two textboxes where we write Name & city. On submitting values of this textboxes should go to other page.
Let’s take an example where we will pass name & city of the person to page myWebpage.aspx using query string.
Let’s say we have two textboxes where we write Name & city. On submitting values of this textboxes should go to other page.
1
2
3
4
5
6
|
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Redirect("myWebpage.aspx?name=" +
this.txtName.Text + "&city=" +
this.txtCity.Text);
}
|
Like this link will form something like this
http://www.localhost.com/myWebpage.aspx?name=&city=
Let’s read this value on page load event of myWebpage.aspx.
http://www.localhost.com/myWebpage.aspx?name=
Let’s read this value on page load event of myWebpage.aspx.
1
2
3
4
5
|
private void Page_Load(object sender, System.EventArgs e)
{
this.txtName.Text = Request.QueryString["name"];
this.txtCity.Text = Request.QueryString["city"];
}
|
Like this we can pass values from one page to another using query string
No comments:
Post a Comment