ASP VB.NET CheckBox CheckedChanged Event

Here’s a small example of how to make a checkbox change a label property:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:CheckBox ID="CheckBox1" runat="server" Text="Make the Label Change!" AutoPostBack="True" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Here’s the VB Codebehind:

Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Label1.ForeColor = Drawing.Color.Red
            Label1.Text = "This is True and Red"
            Label1.ForeColor = Drawing.Color.Green
            Label1.Text = "This is Else<br /> and Green"
        End If
    End Sub
End Class

~ by worldcrossings on July 17, 2010.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: