Wednesday, April 3, 2019

help with variable after click event in vb.net asp

I hope it's ok to post this here. I've done some coding in VB.NET but trying to combine it with webpages now and getting stuck.

This is the VB code for a webform that has 2 buttons. One button reduces the variable by 1 and the other increases by 1.

Clearly my counter is getting reset to 1 each time I leave the click event. I presume that the page is reloading after each event and causing this?? if anyone can look at this snipped and help me I would appreciate it.

Public Class WebForm1

Inherits System.Web.UI.Page

'Protected counter As Integer = 1

Public counter As Integer = 1

Public ImageName = "~/Images/ch" & CStr(counter) & ".jpg"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Label1.Text = counter

End Sub

Protected Sub IBtnBack_Click(sender As Object, e As ImageClickEventArgs) Handles IBtnBack.Click

counter = counter - 1

ImageName = "~/Images/ch" & CStr(counter) & ".jpg"

Label1.Text = counter

Image1.ImageUrl = ImageName

End Sub

Protected Sub IBtnForward_Click1(sender As Object, e As ImageClickEventArgs) Handles IBtnForward.Click

counter = counter + 1

ImageName = "~/Images/ch" & CStr(counter) & ".jpg"

Label1.Text = counter

Image1.ImageUrl = ImageName

End Sub

End Class

help with variable after click event in vb.net asp Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team