CheckBox Text alignment change dynamically in ASP.NET

October 03, 2013 0 Comments

CheckBox Text alignment change dynamically in ASP.NET. By-=default text is aligned to left side . you can change using TextAlign enumeration property. Take a webfrom control and place two button and one checkBox control onit.

lets take an simple example

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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="Gender" />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Left "
            Width="59px" />
        <br />
        <br />
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Right"
            Width="59px" />

Codebehind Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        CheckBox1.TextAlign = TextAlign.Left;

    protected void Button2_Click(object sender, EventArgs e)
        CheckBox1.TextAlign = TextAlign.Right;



Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google