asp.net example - label background image
in this tips we will see how to change the asp.net label control's background. here
we set a background image in label and apply it as a repeatable image. it's make the
label control very different looking from normal label control. in asp.net label control there
are no built in property to setup the label background image. so we need to apply core css here.
we just create a css section in document header and added it as label style attribute.
label-background-image.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.CssClass = "LabelBackgroundImageStyle";
//another way to apply background image in label control.
//Label1.Style.Add("background-image","url(http://1.bp.blogspot.com/-__K7OBRzLR8/UbWycCa51xI/AAAAAAAAKB4/w7cvnG0herU/s1600/bggray.gif)");
//Label1.Style.Add("background-repeat","repeat");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type="text/css">
.LabelBackgroundImageStyle {
background-image:url(http://1.bp.blogspot.com/-__K7OBRzLR8/UbWycCa51xI/AAAAAAAAKB4/w7cvnG0herU/s1600/bggray.gif);
background-repeat:repeat;
}
</style>
<title>asp.net example - label background image</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - label background image
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="click here to set label background image."
Font-Size="XX-Large"
ForeColor="DimGray"
Height="100"
Width="500"
>
</asp:Label>
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="label background image"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to align Label text to right
- How to apply CSS style to a Label
- How to change Label width using CSS
- How to align text to center in a Label
- How to change Label text from JavaScript
- How to databind Label
- How to display html tags in a Label
- How to highlight an item in a DropDownList
- How to create a DropDownList displaying years
- How to apply ListBox auto height