Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Using C# and ASP .Net

Using C# and ASP .Net

Scheduled Pinned Locked Moved ASP.NET
csharpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bthumber
    wrote on last edited by
    #1

    Hi, Using the code-behind, I have two web pages, page 1 and page 2. The user will enter their name into TextBox1.Text on page 1, then press the submit button. Question is how do you get the data (user name) from page 1 to page 2. Please show using C# code:((

    A 1 Reply Last reply
    0
    • B bthumber

      Hi, Using the code-behind, I have two web pages, page 1 and page 2. The user will enter their name into TextBox1.Text on page 1, then press the submit button. Question is how do you get the data (user name) from page 1 to page 2. Please show using C# code:((

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      Hi there, You can use the Session object, e.g. Page #1

      protected System.Web.UI.WebControls.TextBox TextBox1;

      private void Page_Load(object sender, System.EventArgs e)
      {
      if (IsPostBack())
      {
      Session["username"] = TextBox1.Text;
      }

      // ...
      // ...
      // ...
      

      }

      And then in Page #2

      private void Page_Load(object sender, System.EventArgs e)
      {
      // has the username been set?
      string userName = Session["username"];

      // ...
      // ...
      // ...
      

      }

      Hope this helps, Andy

      B T 2 Replies Last reply
      0
      • A Andrew Quinn AUS

        Hi there, You can use the Session object, e.g. Page #1

        protected System.Web.UI.WebControls.TextBox TextBox1;

        private void Page_Load(object sender, System.EventArgs e)
        {
        if (IsPostBack())
        {
        Session["username"] = TextBox1.Text;
        }

        // ...
        // ...
        // ...
        

        }

        And then in Page #2

        private void Page_Load(object sender, System.EventArgs e)
        {
        // has the username been set?
        string userName = Session["username"];

        // ...
        // ...
        // ...
        

        }

        Hope this helps, Andy

        B Offline
        B Offline
        bthumber
        wrote on last edited by
        #3

        Hi Andy, Thank for your help! I'm getting an error: can't implicitly convert type 'object' to 'string'. Page 2 string username = Session["username"];

        A 1 Reply Last reply
        0
        • B bthumber

          Hi Andy, Thank for your help! I'm getting an error: can't implicitly convert type 'object' to 'string'. Page 2 string username = Session["username"];

          A Offline
          A Offline
          Arjan Einbu
          wrote on last edited by
          #4

          string username = Session["username"] as string;


          Have a look at my latest article about Object Prevalence with Bamboo Prevalence.

          B 1 Reply Last reply
          0
          • A Arjan Einbu

            string username = Session["username"] as string;


            Have a look at my latest article about Object Prevalence with Bamboo Prevalence.

            B Offline
            B Offline
            bthumber
            wrote on last edited by
            #5

            Arjan...that last piece of the pie was beautiful!!! It works!!!! Thanks!

            1 Reply Last reply
            0
            • A Andrew Quinn AUS

              Hi there, You can use the Session object, e.g. Page #1

              protected System.Web.UI.WebControls.TextBox TextBox1;

              private void Page_Load(object sender, System.EventArgs e)
              {
              if (IsPostBack())
              {
              Session["username"] = TextBox1.Text;
              }

              // ...
              // ...
              // ...
              

              }

              And then in Page #2

              private void Page_Load(object sender, System.EventArgs e)
              {
              // has the username been set?
              string userName = Session["username"];

              // ...
              // ...
              // ...
              

              }

              Hope this helps, Andy

              T Offline
              T Offline
              theJazzyBrain
              wrote on last edited by
              #6

              Why not use a form and on page 2 do the following:

              string userName = Request.Params["TextBox1"]
              

              Storing information on the session is not wise as it consumes more server memory. theJazzyBrain

              Excellence is not an act, but a habit!

              Aristotle

              A 1 Reply Last reply
              0
              • T theJazzyBrain

                Why not use a form and on page 2 do the following:

                string userName = Request.Params["TextBox1"]
                

                Storing information on the session is not wise as it consumes more server memory. theJazzyBrain

                Excellence is not an act, but a habit!

                Aristotle

                A Offline
                A Offline
                Andrew Quinn AUS
                wrote on last edited by
                #7

                That would depend on what you were storing. Not wise if it was something like connection string information (although yes you could encrypt it) and then want about an object, you would have to implement serialize functionality to be able to restore the state of the object.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups