asp.net example - label width css
this example shown how can we change the asp.net label server control width using simple css.
here we uses label control style property. and we add a css style on style property.
when someone click a button control, it programmatically change the label control's width.
to apply this we need to write a css style section on web pages header section.
label-width-css.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.CssClass = "LabelWidthStyle";
//another way to apply css style in label control.
//Label1.Style.Add("width","475px");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type="text/css">
.LabelWidthStyle {
width:475px;
}
</style>
<title>asp.net example - label width css</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - label width css
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="sample label to test label css width."
BorderColor="Red"
BorderWidth="1"
Font-Size="X-Large"
>
</asp:Label>
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="label width css"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>


- How to align text to center in a Label
- How to change Label text from JavaScript
- How to add a background image to a Label
- How to display none in a Label
- How to encode html in a Label
- How to justify the text in a Label
- How to display a link in a Label
- How to set a default value for DropDownList
- How to add an item at the top of DropDownList
- How to add an item at DropDownList at index 0