This is a question about asp.net webforms and sessionstate. I know this is probably the case when MVC is better, but I need to use WebForms.
In my OnLoad event page, I initialize the object and its properties (one call to db, then some logic for the properties.) I use this object to populate the controls on the page, for example. lblTitle.text = myObj.Title.
Also on this page is an input text field in which the user enters some information, and then clicks the "Save" button. This will call a utility function that will write the contents of the text field to a file and save it. In addition, he should save it to a file with the name contained in myObj.Title.
Here's my problem - due to the stateless aspect of WebForms, after loading the page, myObj is gone. * This means that I cannot do something simple when saving: Util.save (contentsoftextbox, myObj.Title).
So I solved this by writing the value of myObj.Title for the session variable (Session.Add ["title"] = myObj.Title in the OnLoad event of the page. Then, when the save function is called, I use this session variable for my second parameter.
Thanks for reading this.
My question is:
This seems like an unnecessary tricky way to get the job done. It? What else can I do to complete this task?
* right?
source
share