This is a question about asp.net WebForms and sessionstate. I know this is probably a case where MVC is better, but I need to use WebForms.
In my page's OnLoad event, I initalize an object and its properties (one call to a db, then some logic for the properties.) I use this object to populate the controls on the page, eg. lblTitle.text = myObj.Title.
Also on this page is an input textbox, where the user will enter some info and then press a 'save' button. This will call a utility function which will write the contents of the textbox to a file and save it. Moreover, it needs to save it to a file with the name contained in myObj.Title.
Here's my problem - because of the stateless aspect of WebForms, after the page loads, myObj is gone.* Which means I can't do something easy like this on saving: Util.save(contentsoftextbox, myObj.Title).
So I solved it by writing the value of myObj.Title to a session variable (Session.Add["title"] = myObj.Title in the page's OnLoad event. Then when the save function is called, I use this session variable for my 2nd parameter.
Thanks for reading this far.
My question is:
This feels like a needlessly complex way of getting the job done. Is it? What else could I do to accomplish this task?
*right?