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