Lab 6 Code

Default.aspx

Code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="CounterPage" ViewStateEncryptionMode="Always" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Simple Counter with ViewState</title> </head> <body> <form id="mainForm" runat="server"> <div class="counter-container"> <asp:Label ID="counterLabel" runat="server" CssClass="counter-label" Text="Current Count: 0" /><br /> <asp:Button ID="incrementButton" runat="server" Text="Add 2" OnClick="incrementButton_Click" /> </div> </form> </body> </html>

Default.aspx.vb

Code

Partial Class CounterPage
Inherits System.Web.UI.Page

Protected Sub incrementButton_Click(sender As Object, e As EventArgs)
Dim currentCount As Integer = 0

If ViewState("count") IsNot Nothing Then
currentCount = Convert.ToInt32(ViewState("count"))
End If

currentCount += 2
ViewState("count") = currentCount
counterLabel.Text = "Current Count: " & currentCount.ToString()
End Sub
End Class
Web hosting by Somee.com