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. Cookies and code-behind

Cookies and code-behind

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascripthtmlwinforms
6 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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    My current job is mostly windows forms, but I've been called to help edit the aspx pages in the web-application part of the software I'm developing, and I think I'm having some mental-adjustment issues and was hoping to get some help. I have a page that has 2 major elements, a toolbar (with dropdown and textbox sub-elements), and a datagrid. A button on the toolbar calls a .js script that filters the datagrid based on the information entered. What my client has asked for, and what I'm having trouble trying to figure out how to deliver, is how to retain the dropdown and textbox fields through an entire session. I've done some searching, and my original guess of using cookies over viewstate[] seems to be the right one, and I've even found out that with IE (which my client will be using), I can set a cookie to datetime.min to have it expire at the end of the session. My problem is that I'm having trouble trying to figure out where to assign the cookie. I've written a C# function (MakeCookie();) that declares a cookie and assigns the appropriate dropdown/textbox values to it, and I look for the cookie in the Page_Load event, but I'm unsure where (and with what syntax) I should call the MakeCookie function from the aspx. I'm thinking that there must be some element on the body or page tag that I can use, but nothign seems to be jumping out at me. Any ideas? (edited to remove html to get rid of smileys)

    T 1 Reply Last reply
    0
    • D Drew McGhie

      My current job is mostly windows forms, but I've been called to help edit the aspx pages in the web-application part of the software I'm developing, and I think I'm having some mental-adjustment issues and was hoping to get some help. I have a page that has 2 major elements, a toolbar (with dropdown and textbox sub-elements), and a datagrid. A button on the toolbar calls a .js script that filters the datagrid based on the information entered. What my client has asked for, and what I'm having trouble trying to figure out how to deliver, is how to retain the dropdown and textbox fields through an entire session. I've done some searching, and my original guess of using cookies over viewstate[] seems to be the right one, and I've even found out that with IE (which my client will be using), I can set a cookie to datetime.min to have it expire at the end of the session. My problem is that I'm having trouble trying to figure out where to assign the cookie. I've written a C# function (MakeCookie();) that declares a cookie and assigns the appropriate dropdown/textbox values to it, and I look for the cookie in the Page_Load event, but I'm unsure where (and with what syntax) I should call the MakeCookie function from the aspx. I'm thinking that there must be some element on the body or page tag that I can use, but nothign seems to be jumping out at me. Any ideas? (edited to remove html to get rid of smileys)

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      session["dropdownlistvalue"] = dropdownlist.selectedvalue; dropdownlist.selectevalue = session["dropdownlistvalue"].tostring();


      how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      D 1 Reply Last reply
      0
      • T ToddHileHoffer

        session["dropdownlistvalue"] = dropdownlist.selectedvalue; dropdownlist.selectevalue = session["dropdownlistvalue"].tostring();


        how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        D Offline
        D Offline
        Drew McGhie
        wrote on last edited by
        #3

        OK, I looked that up and it seems like it would work instead of the cookies. My question is, however, is there an event that I could handle so I could set the Session[] variable as I was navigating out of the page?

        E 1 Reply Last reply
        0
        • D Drew McGhie

          OK, I looked that up and it seems like it would work instead of the cookies. My question is, however, is there an event that I could handle so I could set the Session[] variable as I was navigating out of the page?

          E Offline
          E Offline
          eggsovereasy
          wrote on last edited by
          #4

          No, but you can set the session variable everytime a menu item is selected so it's always the most recent selection, then on Page_Load load the variable. Asp.net is all server side and there is no message sent to the server when a page closes or the user leaves it, so you can't take action. Probably your biggest adjust from windows forms to asp.net is going to be the separation between client and server.

          D 1 Reply Last reply
          0
          • E eggsovereasy

            No, but you can set the session variable everytime a menu item is selected so it's always the most recent selection, then on Page_Load load the variable. Asp.net is all server side and there is no message sent to the server when a page closes or the user leaves it, so you can't take action. Probably your biggest adjust from windows forms to asp.net is going to be the separation between client and server.

            D Offline
            D Offline
            Drew McGhie
            wrote on last edited by
            #5

            I've been noticing that. Is it possible to set the session variables from the .js scripts that do the filtering (there's a button)?

            G 1 Reply Last reply
            0
            • D Drew McGhie

              I've been noticing that. Is it possible to set the session variables from the .js scripts that do the filtering (there's a button)?

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

              No, the session variables never leave the server. If you want to set a session variable from the client, you have to send the information to the server and do the change on the server.

              --- b { font-weight: normal; }

              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