asp.net example - add image to label
this is a very interesting tutorial. we know asp.net label can hold text value. but here we see how can we show image
in asp.net label control. very simple techniques, just put a html image tag with value as asp.net label text property value.
then the label control show image instead the img tag value. it process the html img tag and finally show the image in label control.
we demonstrate this example by a button click event.
add-image-to-label.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = "asp.net c# examples ebook<br />";
Label1.Text += "<img src='http://2.bp.blogspot.com/-p3CxZbZGPns/UokjtDWar0I/AAAAAAAAUsc/rAiSjEk_HL8/s1600/cover4.png'>";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net example - add image to label</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - add image to label
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="sample label to test image inside label control."
Font-Size="X-Large"
>
</asp:Label>
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="add image to label"
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 align Label text to right
- 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 justify the text in a Label
- How to display a link in a Label