Thursday, May 15, 2008

Cubefield Armour Games

Variables postbacks persistent sources

One problem that we face as we program in asp.net is the fact that the variables declared in a webform "die" after the first postback to save variables between postbacks there are several alternatives, the use of Session, Application or ViewState, which is used depends on what you want to do, very simple I detail when to use each of the 3 options Session

  • : You must use if you want to store variables and objects throughout the session, a session means a connection to the web server from a browser. The variables placed in Session live while the explorer is opened and interacted with the site. to put variables here just to do the following: dim

    xVar
    as integer = 199 Session ("myvariable") = xVar

    and to recover

    dim z as integer = session ("myvariable")
  • Application: Variables stored here while living application live on the web server, usually are placed here and Obet variables to be used by all users using the application, So yes, if one changes the value of the variable stored in application, this change is reflected to all connected users (all sessions). To save variables or objects becomes:

    xVar dim as integer = 199
    Application ("myvariable") = xVar

    and retrieve

    dim z as integer = Application ("myvariable") ViewState
  • : The variables or stored objects that live here live a webform, and ViewState is ASP.Net mechanism to save web control values \u200b\u200bin postbacks, it is actually a hidden variable that the customer comes and goes with the values \u200b\u200bof WebForm controls. What makes this mechanism usually take the opportunity here to save themselves the form variables are important only in the webform, it is therefore not advisable to store them in Session or Application. ViewSat To do it:


    dim as integer = 199 xVar
    Me.ViewState ("myvariable") = xVar

    and retrieve

    dim z as integer = Me.ViewState ("myvariable")

In either the 3 mechanisms have to be careful not to try to retrieve a nonexistent variable that can cause a runtime error and returned the 3 mechanisms are nothing if not variable

For the next installment I'll show you how to save their own objects in these using the serialization mechanisms, something very basic and easy to use. Salu2


Sergio

0 comments:

Post a Comment