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

  • Home
  • SEARCH
  • 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 132883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:20:00+00:00 2026-05-11T06:20:00+00:00

I have the following really simple code <asp:ScriptManager ID=ScriptManager1 runat=server> </asp:ScriptManager> <asp:UpdatePanel ID=UpdatePanel1 runat=server>

  • 0

I have the following really simple code

<asp:ScriptManager ID='ScriptManager1' runat='server'> </asp:ScriptManager>  <asp:UpdatePanel ID='UpdatePanel1' runat='server'> <ContentTemplate>     <asp:PlaceHolder ID='PlaceHolder1' runat='server'>     </asp:PlaceHolder>     <asp:Button ID='Button1' runat='server' Text='Button' onclick='Button1_Click' /> </ContentTemplate> </asp:UpdatePanel> 

And the codebehind

protected void Button1_Click(object sender, EventArgs e) {     Literal literal = new Literal();     literal.Text = DateTime.Now.ToString();     literal.ID = DateTime.Now.Ticks.ToString();      // These both work fine the first time the button is clicked     // but the second time nothing is added.     UpdatePanel1.ContentTemplateContainer.Controls.Add(literal);     PlaceHolder1.Controls.Add(literal); } 

My problem comes in that the Literal control is only ever added once. I’ve scoured google and blog sites (plus books) but without any luck. What am I missing?

  • 1 1 Answer
  • 2 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. 2026-05-11T06:20:00+00:00Added an answer on May 11, 2026 at 6:20 am

    In asp.net, the controls in the ASPX file are automatically generated on each postback. The controls you’ve created are not in the ASPX code so the framework does not create them for you. The first time you execute the Button1_Click method, you add one extra control to the page. The second time you execute the Button1_Click method, you’re on another post back and that first extra button has been forgotten about. So the result of that postback is you get one extra button again.

    This will create one extra control each time you click the button (although the timestamps will update each time you press the button because the controls are being re-created)

    protected void Button1_Click(object sender, EventArgs e) {     int count = 0;      if (ViewState['ButtonCount'] != null)     {         count = (int)ViewState['ButtonCount'];     }      count++;     ViewState['ButtonCount'] = count;      for (int i = 0; i < count; i++)     {         Literal literal = new Literal();         literal.Text = DateTime.Now.ToString();         literal.ID = DateTime.Now.Ticks.ToString();          UpdatePanel1.ContentTemplateContainer.Controls.Add(literal);         PlaceHolder1.Controls.Add(literal);     }             } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 196k
  • Answers 196k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer delete from child_table where not exists (select 1 from parent_table… May 12, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer Object objects = java.lang.reflect.Array.newInstance(Class.forName(classname), 10); For an array of 10… May 12, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer I have definitely seen this before (examples elude me right… May 12, 2026 at 7:07 pm

Related Questions

I'm building an ASP.NET 3.5 application and would like to expose an enum I
I'm after a definitive reference to what ASP.NET code is required to disabled browsers
It is quite possible that I may not have got the point, but I
I have the following html.erb code that I'm looking to move to Haml: <span

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.