Is asp.net webforms a good way to maintain state?

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?

+3
source share
7 answers

. , , , MyObj , .

+1

ViewState? , , , , ?

+5

myObj .

+4
0

= hidden. , .

, , , , , , ..)

0

. In-proc, , , , .

( , , ): box / JSON JavaScriptSerializer

HTML 5

0

, . .

, , , , . , , , , , .

Viewstate, .

, , , . - " ", .

, viewstate. , , viewstate, . , viewstate, , / , .

0

Source: https://habr.com/ru/post/1725083/


All Articles