| Next Tip?
Home » Asp.net

Changing Label Properties at run time

10 March 2010 601 views No Comment
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


–>

Changing Label Properties at run time
To change the properties of the label at run time we need a label whose properties we will change and an event on which we can see the changes that we have made are applied so to solve the purpose of an event I have taken a command button or button whose click event will work for as the triggering event.
A Design view is shown here.
There are three controls:
And following changes are made to their properties.
Label1
ID: lbl_Name
Backcolor: Aqua
BorderColor: #660066
BorderStyle: Double
BorderWidth: 5px
Font:
Bold: True
Italic: True
Name: Book Antiqua
ForeColor: Red
Text: Name
ToolTip: Enter Your First Name
Label2
ID: lbl_result
Button1
ID : btn_click
Text: Click
Then you can either double click on the button in the Default.aspx page or you can double click on the combobox in the properties window under events in front of click event in order to generate the click event.
Once you will do that you will see the following window.
Add the following code to the event and run the project
Now the event will look like
protected void btn_click_Click(object sender, EventArgs e)
{
//lbl_Name.Text = “Meetu Choudhary”;
lbl_Name.BackColor = System.Drawing.Color.Blue;
lbl_Name.ForeColor = Color.Red;
lbl_Name.Font.Bold = false;
lbl_Name.Font.Italic = false;
lbl_Name.Font.Underline = true;
lbl_Name.BorderColor = Color.Black;
lbl_Name.BorderStyle = BorderStyle.Solid;
lbl_result.Text = lbl_Name.Text;
}
To use the following line
lbl_Name.ForeColor = Color.Red;
You need to add
using System.Drawing;
In the using section.
Now you can run the project and when you will click the button at run time you will see the changes.
You can check the video for the above article at:

Thanks and Regards
Meetu Choudhary
Microsoft MVP (ASP.Net)
DNS MVM Awardee | Microsoft Certified Professional | Microsoft Certified Technology Specialist |
Co-founder / Webmaster : www.jaipurmentor.com | www.msdotnetmentor.com | www.indiaalt.net | Lead Editor / Webmaster : www.dotnetspider.com | www.silverlightclub.com | interview.msdotnetheaven.com | forum.msdotnetheaven.com | My Blog : http://aspnetbymeetu.blogspot.com | My Profile : www.google.com/profiles/meetuchoudhary

Popularity: unranked

Post to Twitter Tweet This Post

Related posts:

  1. Changing properties of textbox in visual studio 2010 Changing properties of textbox in visual studio 2010 To...
  2. Textbox Properties Textbox Properties In this article I will be talking...
  3. Isolated Storage in the Silverlight Application Isolated Storage Isolated Storage in the Silverlight Application Definition: Isolated...
  4. Progress Bar demo application Hi All, I am Developing this Application just to help...
  5. Sending Mails with attachments using Gmail Tweet This Post...

Related posts brought to you by Yet Another Related Posts Plugin.

Ads by Lake Quincy Media

Leave your response!

You must be logged in to post a comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes