Thread: Passing variables to another form

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    215

    Passing variables to another form

    Im working in ASP.net with C#, and I want to pass hidden form variables from one page when I click a link, to another page. My problem is I dont know how to do that. I was thinking about using Reqest.Form or something, but I cant figure out how that would work.

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    19
    Why not put them in the session or cache?

    Anyways the proper way to do this is to create a reference.

    In the old page add

    Code:
    <%@Page ClassName="SenderPage" %>
    in the script add something like this (property)
    Code:
    public string SomeVar{
                       get{return TextBox1.Text;}
    }
    now in recipient form

    Code:
    <%@Reference Page="SenderPage.aspx" %>
    Code:
    SenderPage sp;
    
    void page_load(object sender, EventArgs e){
                     sp = (SenderPage) Context.Handler;
    }
    This should do the job. But you can always use session variables.

  3. #3
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    This always worked for me. You can pass objects to other forms this way, too. This example uses a simple string.

    Form 1:
    Code:
    MyForm mf = new MyForm(ref name);
    mf.Show();
    this.Hide();
    Form 2:
    Code:
    // in constructor
    public MyForm(ref string name) {
       this.name = name;
    }
    Edit: Oops, I didn't read the extra details in the original post.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    19
    This seems to be for Windows forms. ASP.net are webforms and i dont know if they support such a thing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing variables to system
    By redruby147 in forum C Programming
    Replies: 4
    Last Post: 09-18-2008, 06:28 PM
  2. Displaying values of variables to a Form
    By Cielo in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2008, 03:47 AM
  3. C# in ASP.Net - Passing complex variables
    By Llam4 in forum C# Programming
    Replies: 3
    Last Post: 01-19-2008, 02:53 AM
  4. Passing variables to system() function?
    By carter192 in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 09:44 PM
  5. question on passing variables
    By dirgni in forum C++ Programming
    Replies: 5
    Last Post: 12-04-2002, 04:36 PM