how to change font size style of label dynamically in asp.net

Posted by Shanky11 under ASP.NET on 9/20/2013 | Points: 10 | Views : 29505 | Status : [Member] | Replies : 5
i have created a website and in that thre is a label i want that label change dynamically
that is size font family etc




Responses

Posted by: Allemahesh on: 9/20/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Shanky,

You can use the Label.Attributes.Add() method to change the label size font family etc dynamically

Here is an example:-

Default.aspx page

<head runat="server">

<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbltest" runat="server" Text="Test"></asp:Label>
</div>
</form>
</body>
</html>


Default.aspx.cs page

protected void Page_Load(object sender, EventArgs e)

{
lbltest.Attributes.Add("style", "font-size:50px; color:Red; font-weight:bold;");
}


Happy Coding
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/20/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

check this

Label lbl1 = new Label();
lbl1.Style.Add("style", "Arial, Tahoma;Color:red;");
lbl1.Text = "Jesus Never Fails";
form1.Controls.Add(lbl1);

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/20/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try this one using Jquery

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<style type ="text/css">
.FntFamly
{
font-family: Arial Tahoma Times New Roman;
color:Red;
}
</style>
<script>
$(document).ready(function () {
$("#lbl1").html('Jesus Never Fails.');
$("#lbl1").addClass("FntFamly");
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbl1" runat ="server"></asp:Label>
</div>
</form>
</body>
</html>

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Sample example:
<%@ Page Language="C#" %>  


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.ForeColor = System.Drawing.Color.Magenta;
}
protected void Button2_Click(object sender, System.EventArgs e)
{
Label1.ForeColor = System.Drawing.Color.DodgerBlue;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set, change label ForeColor (font, text color) programmatically</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">Label Example: ForeColor</h2>
<asp:Label
ID="Label1"
runat="server"
Text="Click the Button for change Label color."
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
ForeColor="SeaGreen"
Text="Label ForeColor Magenta"
OnClick="Button1_Click"
Font-Bold="true"
/>
<asp:Button
ID="Button2"
runat="server"
Font-Bold="true"
ForeColor="SeaGreen"
Text="Label ForeColor DodgerBlue"
OnClick="Button2_Click"
/>
</div>
</form>
</body>
</html>


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this links too
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fontinfo%28v=VS.80%29.aspx

Dynamic CSS Styling in ASP.NET: A Flexible Approach
http://www.codeproject.com/Articles/14033/Dynamic-CSS-Styling-in-ASP-NET-A-Flexible-Approach

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response