Home > Net >  About VB.net pages variables
About VB.net pages variables

Time:10-06

Dim intA1 as int16

Private Sub Bill_test1_Init (sender As Object, As EventArgs e) Handles Me. The Init
IntA1=10
If Not Page. IsPostBack Then
Sub1
End the If
End Sub


Private sub sub1
IntA1 intA1 + 5=
End sub


Private sub sub2
IntA1=intA1 + 100
End sub

Protected Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
Sub2
Msgbox (intA1)
End Sub

Now hope for the button, click can get is 115 for the first time, the second click on 215, has been down, rather than has been the 110
How to define such variables, please?

CodePudding user response:


Protected Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
Sub2
sub1
Msgbox (intA1)
End Sub

CodePudding user response:

First you need to understand a little, that every time you click on the button, is requests the server page, the page code are new, so the resulting value is 110,
If you want to save this value will need to use the session,



Protected Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
IntA1=Session. The Item (" intA1 ")
Sub2
Sub1
The Session. The Item (" intA1 ")=intA1
Msgbox (Session. The Item (" intA1 "))
End Sub

CodePudding user response:

Now that do webfrom intA1 the variables don't use, to achieve with a page tag lable, data type conversion, and use it every time you state make it automatic maintenance good,

CodePudding user response:

Dim the static intA1 as int16
Or use session, application, cache, etc
  • Related