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. ASP.NET - C# passing a variable to the page with postback

ASP.NET - C# passing a variable to the page with postback

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelpquestion
7 Posts 3 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.
  • P Offline
    P Offline
    Phivos Stylianides
    wrote on last edited by
    #1

    Hi, I have a method that retrieves a variable with a click of a LinkButton. I need to use that variable in an other method but it becomes null for some reason. I guess that happens because of the page postback every time and since i have an initialization command at the beginning of my code it makes it null again. So should i pass an argument with the page postback or disable the linkbutton's postback. And How could i do any of those? Your help is greatly appreciated. phivos

    F 1 Reply Last reply
    0
    • P Phivos Stylianides

      Hi, I have a method that retrieves a variable with a click of a LinkButton. I need to use that variable in an other method but it becomes null for some reason. I guess that happens because of the page postback every time and since i have an initialization command at the beginning of my code it makes it null again. So should i pass an argument with the page postback or disable the linkbutton's postback. And How could i do any of those? Your help is greatly appreciated. phivos

      F Offline
      F Offline
      ffowler
      wrote on last edited by
      #2

      Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback? Just wanted to make a note that I am a newbie and am trying to contribute to this site as others have helped me.

      G 1 Reply Last reply
      0
      • F ffowler

        Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback? Just wanted to make a note that I am a newbie and am trying to contribute to this site as others have helped me.

        G Offline
        G Offline
        gspiteri
        wrote on last edited by
        #3

        ffowler wrote:

        Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback?

        Have to agree with you FFowler there hold the variable value in session or viewstate but could you elaborate on the sequence of events you are trying to implement?

        F P 2 Replies Last reply
        0
        • G gspiteri

          ffowler wrote:

          Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback?

          Have to agree with you FFowler there hold the variable value in session or viewstate but could you elaborate on the sequence of events you are trying to implement?

          F Offline
          F Offline
          ffowler
          wrote on last edited by
          #4

          I HELPED, I HELPED.....finally! :laugh:

          1 Reply Last reply
          0
          • G gspiteri

            ffowler wrote:

            Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback?

            Have to agree with you FFowler there hold the variable value in session or viewstate but could you elaborate on the sequence of events you are trying to implement?

            P Offline
            P Offline
            Phivos Stylianides
            wrote on last edited by
            #5

            Yes exactly, does any of you guys know how to assign it as a Session variable and then how to retrieve it back? Thanks a lot!

            G 1 Reply Last reply
            0
            • P Phivos Stylianides

              Yes exactly, does any of you guys know how to assign it as a Session variable and then how to retrieve it back? Thanks a lot!

              G Offline
              G Offline
              gspiteri
              wrote on last edited by
              #6

              Session["Giveitaname"] = value //if the value you are storing is string i suggest do this if(!string.IsNullorEmpty(Session["Giveitaname"].toString()) { newvalue = Session["Giveitaname"].tostring(); } //otherwise just check if null then cast it accordingly

              P 1 Reply Last reply
              0
              • G gspiteri

                Session["Giveitaname"] = value //if the value you are storing is string i suggest do this if(!string.IsNullorEmpty(Session["Giveitaname"].toString()) { newvalue = Session["Giveitaname"].tostring(); } //otherwise just check if null then cast it accordingly

                P Offline
                P Offline
                Phivos Stylianides
                wrote on last edited by
                #7

                Thank's a lot for your post! Works!

                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