Makai Studio
Imi ‘Ike - Seeker Of Knowledge
Imi-?ike

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

November 7, 2007 02:58 by jdelpay

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

AddThis Social Bookmark Button

Currently rated 5.0 by 6 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
,
Categories: ASP.Net
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

Related posts

Comments

November 11. 2007 02:47

Graddy

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

Graddy

November 13. 2007 21:18

madhavi

text

madhavi

January 15. 2008 17:27

Ashutosh

thanks a lot.

Ashutosh

May 4. 2008 02:15

pzurich

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?

pzurich

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

May 16. 2008 14:38