Home » ASP.Net

ASP.NET 2.0 - Transferring Page Values to Another Page - C# Sample

7. November 2007 by jdelpay 8 Comments

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"];

Comments

Graddy
United States Graddy said:

When are you going to post a tutorial on how to send a form result to an email adress?

pzurich
Singapore pzurich said:

does this also apply to a scenario where in i just want to send a value ona another page but still be on the same page?

Shahrooz
Iran Shahrooz said:

Tanx For u #

Ricardo
Brazil Ricardo said:

its poor.
if i have a form with 100 values, i'll need to type each one on the response.redirect?!?!?!??!

Nazila
Australia Nazila said:

It was awesome! Thank you so much for your valuable info. I had googled alot , but couldn't find a straight forward info like this. THANKS!

masthan
India masthan said:

lo coooool

sathish
India sathish said:

thank u.........  this code is very useful for me..

asipo
asipo said:

That is a like post method, what if I want to send like get method?