How to apply CSS style in the Label control from code-behind in ASP.NET in VB.NET

You can apply CSS style from code behind by accessing the properties of the control with the help of its Id. Most of the CSS styles can be applied using the Font property and its sub properties of the Label control. However you can use ForeColor and BackColor directly from the Label control.


<%@ Page Language=”vb” AutoEventWireup=”false” CodeBehind=”TestApplyCSS.aspx.vb”

Inherits=”TextChange.TestApplyCSS” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=””>

<head runat=”server”>

<title>Apply CSS style in the Label control from code-behind</title>



<form id=”form1″ runat=”server”>


<asp:Label ID=”LabelTest” runat=”server” Text=”My test label”></asp:Label>







Public Class TestApplyCSS

Inherits System.Web.UI.Page

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

Dim FontNames As String() = {“Arial”, “Verdana”}

LabelTest.Font.Names = FontNames

LabelTest.Font.Bold = True

LabelTest.Font.Size = FontUnit.Large

LabelTest.ForeColor = Drawing.Color.Black

LabelTest.BackColor = Drawing.Color.LightGray

End Sub

End Class