We help IT Professionals succeed at work.

how do you pass values across pages  using Server.Transfer  in NET 2.0 C# Web

RSSIAdmin
RSSIAdmin asked
on
870 Views
Last Modified: 2012-05-05
using Server.Transfer  as follows:

on web page1 I have this:

public string Name
{
      get
      {
            return TextBox1.Text;
      }
}

private void Button1_Click
(object sender, System.EventArgs e)
{
      Server.Transfer("webpage2.aspx");
}


on webpage2  or Destination Web Form I have this:

private void Page_Load
(object sender, System.EventArgs e)
{
      //create instance of source web form
      webpage1  wf1;
      //get reference to current handler instance
      wf1=(webpage1 )Context.Handler;
      Label1.Text=wf1.Name;
      }
}

THE ERROR MESSAGE I GET IS:

The type or namespace name 'webpage1' could not be found(are you missing a using directive or an assembly reference?)  ??

PLease show me how to fix this error???


Comment
Watch Question

You could just use a GET form variable:

Add "Name" to the URL like this:

private void Button1_Click
(object sender, System.EventArgs e)
{
     Server.Transfer("webpage2.aspx?Name=" + Name);
}


Page two would look like this:

private void Page_Load
(object sender, System.EventArgs e)
{
     Label1.Text=Request.QueryString["Name"].ToString();
}
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
I've never used Context.Items.  Great answer YZlat.  I'll have to try that out too.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.