Introduction
As developper We always come into situations in which we need to transfer values from one page to another page. In this article, I will show you some ways of transferring values from one page to another page. You can see how this work by visiting http://www.makaistudio.com/inquiry.aspx.
Using Response.Redirect
Let's first see how to transfer using Response.Redirect method. Let's says you have a text box with data in it when you Press the finish submit or finish button.
Tip: Sometimes we want to transfer to another page inside the catch exception, meaning exception is caught and we want to transfer to another page. If you try to do this, it may give you a System.Threading exception. This exception is raised because you are transferring to another page leaving behind the thread running. You can solve this problem using:
Response.Redirect("WebForm.aspx",false);
This tells the compiler to go to page "WebForm.aspx", and "false" here means that don't end what you were doing on the current page. You should also look at the System.Threading class for threading issues. Below, you can see the C# code of the button event. "txtName" is the name of the text field whose value is being transferred to a page called "WebForm.aspx". "Name" which is just after "?" sign is just a temporary response variable which will hold the value of the text box.
private void Button1_Click(object sender, System.EventArgs e)
{
// Value sent using HttpResponse
Response.Redirect("WebForm.aspx?Name="+txtName.Text);
}
Now, where do I collect the values? First, we check that the value entered is not null. If it's not, then we simply display the value on the page using a Label control. Note: When you use Response.Redirect method to pass the values, all the values are visible in the URL of the browser. You should never pass credit card numbers and confidential information via Response.Redirect.
if (Request.QueryString["Name"]!= null)
Label3.Text = Request.QueryString["Name"];
Visit:
Makai Studio
Currently rated 5.0 by 6 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5