transferring data to different page

R

Rani

hi guys I don't know if this is the right place for it but
I created 2 pages
in page one there is a text box in which the user enters his name,
in page 2 there is a the same text box.
I would like the data to be transferred automatically to the second page
how do I do that ?
thanks
 
K

Karl Seguin

yes, it's the right place..and how is the user getting from page one to page
2? is he or she clicking on a link or a button?

There are a couple ways, but none are automatic...you need to grab the data
on the postback to page 1 and redirect/transfer to page 2..

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("page2.aspx?value=" + textbox.Text);
}

or using Context.Items and Server.Transfer


and in page2 you get the value and populate the other textbox

Page_Load
TextBox.Text = Request.QueryString["value"];
end


the above is pretty crappy code (no error check and stuff), but not 100%
sure what mechanism you already have in place...

Karl
 
S

Steve C. Orr [MVP, MCSD]

Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetbips.com/displayarticle.aspx?id=79
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top