How to Set or Change Label Text 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->Add(you can change the name,here i change it from Default2.aspx To LabelControl.aspx)


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 text.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.Text = "You Have Clicked The Button";//just copy this line

    }
6.click F5->ok.
Before Button Click

After Clicking the Button


No comments:

Post a Comment