Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:15:25+00:00 2026-06-03T14:15:25+00:00

I am generating some text in the code-behind of web page on button click

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:15:26+00:00Added an answer on June 3, 2026 at 2:15 pm

    Instead of a StackPanel, use a placeholder

    <asp:PlaceHolder id="ph1" run="server" />
    

    You can then use ph1.Controls.Add(…

    Regards to styling the label, you can use label1.Style.Add(“color”, “red”)

     for (int i = 0; i <= 2; i++)
            {
                Label txtLabel1 = new Label(); //Generating a label
                txtLabel1.Text = i.ToString();
                txtLabel1.Style.Add("Color", "Red");
                ph1.Controls.Add(txtLabel1);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a very simple asp.net web page for generating some HTML. The idea
I am generating an HTML form, which contains some code in a text area.
My application is programmatically generating some html code like this: <div class=container> <div class=class1>
Via PHP, i'm generating some JavaScript code, witch looks like this: <script type=text/javascript> $(window).load(function()
I am generating dynamically some selects in a jsp page with javascript. The code
I am generating some PDFs with dompdf, which contains some text and images in
There is some code in our system for automatically generating self-signed certificates into a
I'm generating some javascript in my PHP code, and I need to assign some
I found some code for generating CSS3 buttons which I'm using on my site.
So I have some php code that is generating links, and for the url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.