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 8275717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:09:54+00:00 2026-06-08T08:09:54+00:00

protected void Page_Load(object sender, EventArgs e) { Label myLabel = new Label(); myLabel.Text =

  • 0
protected void Page_Load(object sender, EventArgs e)
{

Label myLabel = new Label();
myLabel.Text = "Testing 1 2 3";
}

If I create this Label object in the code behind, and it has no < asp:Label > tag on the main page, how can I put this Label somewhere on the page?

I want to dynamically create controls based on information out of a database. From there, I want to place the controls onto the webpage. I can’t predefine places for them because the number and types of controls will change.

What’s the best way to do this?

What if I already have something on my page, such as a table, and I wanted to place the control after the end of the table.

  • 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-08T08:09:56+00:00Added an answer on June 8, 2026 at 8:09 am

    You must add it to the page’s control-collection somewhere.

    this.Controls.Add(myLabel);
    

    Instead of adding it directly to the page, i would use PlaceHolders or Panels as container control. You need to recreate dynamically created controls on every postback in page_load at the latest with the same ID as before(to reload ViewState and trigger events).

    You should use CSS to control the layout of the controls.

    An alternative approach would be to use a web databound control like Repeater which is easier and maintains controls and their state automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: protected void Page_Load(object sender, EventArgs e) { nome_Txt.Text = Profile.dados_pessoais.nome; }
this is the simple code: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
This protected void Page_Load(object sender, EventArgs e) { RadioButtonList1.Items.Add(new ListItem(London,1)); RadioButtonList1.Items.Add(new ListItem(Paris, 2)); }
Code Behind (C#): protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack)
I have a code like this. <script runat=server> protected void Page_Load(object sender, EventArgs e)
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetLeft.Value = invited.GetInviteCountByWeb().ToString(); HttpCookie
Then: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBoxList1.Items.Add(new ListItem(item1)); CheckBoxList1.Items.Add(new
In the pageload i populate a dropdownlist like this: protected void Page_Load(object sender, EventArgs
I have AutoEventWireup=true and in my code behind protected void Page_Init(object sender, EventArgs e)
protected void Page_Load(object sender, EventArgs e) { Button quote = new Button(); Button reply

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.