ViewState lost when updating in UpdatePanel?

Instead of using a Session object or storing in a database, I save the temporary variables that I need to save the ViewState variables. For example, ViewState ("MyField1") = 1

When the user clicks the Rrefresh browser button, Page.IsPostback returns to False and the ViewState is missing.

My question is. If the user can blow away the ViewState with a refresh, why use it?

I know that Refresh sends the last page submitted, why is W._spostback reset False and ViewState reset?

Cry me if you want to create a potential question, but I read other posts here and it doesn't sink in ...

Update original post:

Now I think this is due to postbacks that are executed as a result of clicking on the buttons that are within the UpdatePanel. Can someone help shed some light on this?

+3
source share
5 answers

When the client refreshes its browser, it re-sends the last full page request issued by the client (which may be GET or POST ). It never repeats AJAX requests, such as those created by update panel event triggers ("partial back pages").

That Page.IsPostbackis false, when you update a page means that your original request is GET, so this is what is likely to occur:

1) - , , ( ASP.NET , , , ). ASP.NET , - URL.

2) UpdatePanel, , MyField 1. UpdatePanel , .

, POST , , , .

"", 1 , , .

+4

ViewState? ViewState? , oyu , asp.net LoadViewState().

+1

, updatepanel, . , , WebForms -, mvc.

, , updatepanel , , . , dropdown2, dropdown1.

, .

+1

: " - ".

Viewstate , , , , . - , .

, , datagrid, , , click , .

ViewState , HTML, . SessionState , , - db , .

, .

0

, , similair , form_load:

me.myProperty = me.myProperty

Public Property myProperty() as String
Get
  If Not IsNothing(ViewState("data")) Then
    Return CType(ViewState("data"), String)
  Else
    Return String.Empty
  End If
End Get
Set(value As String)
  ViewState("data") = value
End Set
0

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


All Articles