asp.net example - label padding
we are familiar with padding. but by default asp.net label control have no property to set change
padding value. so the label text display at the edge of control. if we want to show text after 20 pixel then
we need to take help from css. in this example we add a css style padding in asp.net label control. we place the
css section in web page header block.
label-padding.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.CssClass = "LabelPaddingStyle";
//another way to apply padding in label control.
//Label1.Style.Add("padding","50px");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type="text/css">
.LabelPaddingStyle {
padding:50px;
}
</style>
<title>asp.net example - label padding</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - label padding
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="sample label to test label padding."
BorderColor="HotPink"
BorderWidth="1"
Font-Size="X-Large"
Width="350"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="label padding 50px"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>


- How to add an onClick event to a Label
- How to create a multiline Label
- How to change Label width using CSS
- How to align text to center in a Label
- How to databind Label
- How to display html tags in a Label
- How to trim text with ellipsis in a Label
- How to display an image in a Label
- How to add margin to a Label
- How to add top margin to a Label