Thursday, 15 April 2010

c# - How to declare common variable for all action in a asp.net page -



c# - How to declare common variable for all action in a asp.net page -

i have 1 asp.net page next , button , variable "i", each time click next or button, variable "i" increment or decrease 1. how declare variable i? don't want utilize "public static int i" should utilize session or viewstate? there improve ways this?

the view state state of page , controls. automatically maintained across posts asp.net framework.

every time page posts back, starting on scratch - initialized 0, example, 0 again. because server doesn't know lastly time page ran - knows clicked button submits form that.

when page sent client, changes in properties of page , controls determined , stored in value of hidden input field named _viewstate. when page 1 time again post _viewstate field sent server http request.

as on incrementing variables in asp.net on button click

if need persist value across postbacks, standard method utilize viewstate:

public property mycounter() integer dim val object = viewstate("mycounter") homecoming if(val isnot nothing, cint(val), 0) end set(byval value integer) viewstate("mycounter") = value end set end property

it's possible utilize session, persist value across pages , requests life of user's session. work, can utilize same sample above, replacing viewstate session.

c# asp.net

No comments:

Post a Comment