How to change Background color of label programmatically in ASP.NET

 1.File->New->Website->(left side select visual c#) ASP.NET Web Site->ok

2.Now You will see a Default.aspx page.
To create your own page->click on dropdown list below Edit->click Add new item->Select Web Form->click Add

3. Click Split(to see Design and code View simultaniously)->From ToolBox Drag and Drop a Label to Design window->Right click on label->select properties->(look for text property) change text property from label to "This text will change when i click the Button".

4.Drag and drop a button below label->Right click on Button->select properties->change text property from Button to "change back color.Your window should look like this.


5.Double click on the Button(or Right click the Button select view code)->then write this code

protected void Button1_Click(object sender, EventArgs e)//do not write this
    {
        Label1.BackColor = System.Drawing.Color.Violet;
    }
6.click F5->ok.
Before Click








After Click the Button








  If you have any problem with this article just leave a comment.

No comments:

Post a Comment