I am generating some text in the code-behind of web page on button click event. Earlier, in one of my desktop application, I was doing something like this.
For e.g.:
public void button_click(object sender, EventArgs e)
{
for(i=0;i<=2;i++)
{
Label txtLabel1 = new Label(Text=i.ToString(), Color=Blue}; //Generating a label
StackPanel1.Children.Add(txtLabel1); //Adding a label to stack panel on the desktop app
}
for(j=0;j<=3;j++)
{
Label txtLabel2 = new Label(Text=j.ToString(), Color=Red}; //Generating a label
StackPanel2.Children.Add(txtLabel1); //Adding a label to stack panel on the desktop app
}
}
I do not have much experience with web development and so I am a little confused on how to do the similar thing in my ASP.NET website. In my .aspx.cs code, I can generate the strings but from the code-behind, how do I add them to the page along with their color properties as well. Thanks in advance!
Instead of a StackPanel, use a placeholder
You can then use ph1.Controls.Add(…
Regards to styling the label, you can use label1.Style.Add(“color”, “red”)