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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:55:15+00:00 2026-05-23T18:55:15+00:00

protected void addMoreDay_btn_Click(object sender, EventArgs e) { Control OneMoreDay = LoadControl(~/controls/Days/DayAdd.ascx); Days_div.Controls.Add(OneMoreDay); } I

  • 0
protected void addMoreDay_btn_Click(object sender, EventArgs e)
        {
            Control OneMoreDay = LoadControl("~/controls/Days/DayAdd.ascx");
            Days_div.Controls.Add(OneMoreDay);
        }

I load my userControl dynamically to a div element .. but the problem is that it works only once! .. I mean I click the addMoreDay_btn button and it works then I try to click it again it won’t create another instance of my control!

Edit

I think it works but it doesn’t save the last created one .. it just replaces it with the newly created control .. and still I don’t how to solve this! =S

  • 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-05-23T18:55:15+00:00Added an answer on May 23, 2026 at 6:55 pm

    The problem is occurring because the dynamically added control is being destroyed on each postback right before it is created again. In order to have dynamic controls persist across postbacks, you’ll have to add them every time the page posts back.

    Try the following code. Notice that the controls are being added in the Page_Init method:

    protected void addMoreDay_btn_Click(object sender, EventArgs e)
    {
        Control OneMoreDay = LoadControl("~/controls/Days/DayAdd.ascx");
        Days_div.Controls.Add(OneMoreDay);
        Session["MyControl"] += 1
    }
    
    
    protected void Page_Init(object sender, EventArgs e)
    {
        for (int i = 1; i <= (int)Session["MyControl"]; i++) {
            Control OneMoreDay = LoadControl("~/controls/Days/DayAdd.ascx");
            Days_div.Controls.Add(OneMoreDay);        
        }
    }
    

    See here

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

Sidebar

Related Questions

protected void Button1_Click(object sender, EventArgs e) { System.Collections.ArrayList list = new System.Collections.ArrayList(); list.Add(abc); list.Add(xyz);
Then: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBoxList1.Items.Add(new ListItem(item1)); CheckBoxList1.Items.Add(new
This protected void Page_Load(object sender, EventArgs e) { RadioButtonList1.Items.Add(new ListItem(London,1)); RadioButtonList1.Items.Add(new ListItem(Paris, 2)); }
Page Load: protected void Page_Load(object sender, EventArgs e) { tb.Columns.Add(Id, typeof(int)); tb.Columns.Add(FileName, typeof(string)); tb.Columns.Add(FilePath,
protected void Button3_Click(object sender, EventArgs e) //export { GridView2.AllowPaging = false; GridViewExportUtil.Export(Сводка.xls, this.GridView2); GridView2.AllowPaging
protected void GridView1_DataBound(object sender, EventArgs e) { GridView1.Columns[0].ItemStyle.Width = 400; <asp:GridView ID=GridView1 runat=server DataSourceID=ObjectDataSource1
This works just fine: protected void txtTest_Load(object sender, EventArgs e) { if (sender is
Shouldn't PostBack be checked before Session protected void Page_Load(object sender, EventArgs e) { if
protected void btnFind_Click(object sender, EventArgs e) { if (zipcode.Text != ) { litAddress.Text =
protected void rgStateTax_PreRender( object sender, EventArgs e ) { if( rgStateTax.MasterTableView.IsItemInserted ) { foreach(

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.