Results 1 to 4 of 4

Thread: Get a value from another page

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Resolved Get a value from another page

    How can you retrieve a value from one page to another?

    For example if you have Webform1 and Webform2 in the Namespace WebApplication1 I would like to do this:

    WebForm1.aspx

    Code:
    .
    .
    .
    	public class WebForm1 : System.Web.UI.Page
    	{
    		// give public access
    		public System.Web.UI.WebControls.TextBox TextBox1;
    		protected System.Web.UI.WebControls.Button Button1;
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			// Put user code to initialize the page here
    		}
    
    .
    .
    .
    WebForm2.aspx

    Code:
    .
    .
    .
    	public class WebForm2 : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.TextBox TextBox1;
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			TextBox1.Text = WebForm1.TextBox1.Text;
    			// Put user code to initialize the page here
    		}
    .
    .
    .
    The error is:

    An object reference is required for the nonstatic field, method, or property 'WebApplication1.WebForm1.TextBox1'
    Last edited by wey97; Nov 10th, 2004 at 09:50 AM.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You can do this many ways.

    1. Querystring. "WebForm2.aspx?MyText=testtext"

    2. Server.Transfer (I haven't done this, but I think you can do this.)

    3. Session variable. Before you leave page 1, set a session variable:
    Session("MyValue") = text1.text
    In page 2, get the value:
    text2.text = Session("MyValue")

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    For Server.Transfer, you would allow the form to submit and in the submit button click event you would put this code
    VB Code:
    1. Server.Transfer("nextPage.aspx", True)
    2. 'True means maintain the state of the form,
    3. 'so the form elements can be requested from the nextPage.aspx page.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You can cast the Handler Property to get a ref back to the transfering page and access any public members that way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width