Click here to Skip to main content
13,046,176 members (58,613 online)
Rate this:
Please Sign up or sign in to vote.
Hi all

My problem:
I want to create a label dynamically.

Example:In every 10 second i want to create a label with different name.
Label lblTest = new Label();

for 1st time lblTest.Text = "1 username";
after 10 second i want to create another label and assign the text as "2 hi hello"
after 10 second again create another label and assign the text as "3 username password why"
and so on

How to create a label so that it will store all the data but in different labels dynamically and how to retrieve all the labels after each 50 second?

Means :In first 50 second it will show 5 label ,after next 50 second it will show 10 labels and so on.

How to achieve this?

Please suggest

Thanks in advance.
Posted 18-Apr-12 4:23am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have tagged both ASP.NET & Winforms here.
Read about Timer control/Class. It would help you in what you need! (Would not ask why such a odd behaviour!)

ASP.NET Timer control: Timer control[^]
Winforms: Timer Class[^]
Nelek 18-Apr-12 16:54pm
I think you failed in voting, there is no votes of 5 so far
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hi ,
Regarding to the First solution you should do that also for web
int countTimes = 0;
   protected void Timer1_Tick(object sender, EventArgs e)
       if (ViewState["countTimes"] == null)
           countTimes = 1;
           countTimes = Convert.ToInt32(ViewState["countTimes"]);
       for (int i = 0; i < countTimes; i++)
           Label lbl = new Label();
           txtSkill.ID = "lbl" + i;
       countTimes = countTimes + 1;
       ViewState.Add("countTimes", countTimes);

for windows
int i = 1;
     private void timer1_Tick(object sender, EventArgs e)
         Button button1 = new Button();
         button1.Location = new System.Drawing.Point(105 + 20 * i, 92 + 20 * i);
         button1.Name = "button" + i;
         button1.Size = new System.Drawing.Size(75, 23);
         button1.TabIndex = 0 + i;
         button1.Text = "button" + i;
         button1.UseVisualStyleBackColor = true;
     private void Form1_Load(object sender, EventArgs e)

Best Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 19 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100