1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
Partial Public Class WebOpen
Inherits System.Web.UI.Page
Dim Txt_Année As Integer
Dim objID As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Création identifiant unique
If Not Page.IsPostBack Then ViewState("ID") = Guid.NewGuid.ToString
'objID sert de clé pour retrouver l'obj dans le cache
objID = "MonInt|" & ViewState("ID").ToString
If Page.IsPostBack Then
Txt_Année= CType(GetObjectFromCache(objID), integer)
else
Txt_Année = Date.Today.Year
End If
txtAnnéeUnivD.Text = Txt_Année & " / " & Txt_Année + 1
End Sub
Public Function GetObjectFromCache(ByVal ObjName As String) As Object
Dim _Cache As System.Web.Caching.Cache = Web.HttpContext.Current.Cache
If _Cache(ObjName) Is Nothing Then
Return Nothing
Else
Return _Cache(ObjName)
End If
End Function
Public Sub SetObjectToCache(ByVal ObjName As String, ByVal obj As Object)
If ObjName Is Nothing Or obj Is Nothing Then Exit Sub
Dim _Cache As System.Web.Caching.Cache = Web.HttpContext.Current.Cache
_Cache(ObjName) = obj
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Txt_Année = Txt_Année + 1
txtAnnéeUnivD.Text = Txt_Année & " / " & Txt_Année + 1
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Txt_Année = Txt_Année - 1
txtAnnéeUnivD.Text = Txt_Année - 1 & " / " & Txt_Année
End Sub
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
SetObjectToCache(objID, obj)
End Sub |
Partager