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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:28:09+00:00 2026-05-25T17:28:09+00:00

I have a user control which is being loaded to the page dynamically after

  • 0

I have a user control which is being loaded to the page dynamically after performing a postback within an UpdatePanel.

Then I’m performing another postback for saving, where I would like to access the user input for the controls within that user control (for example, a grid with a checkbox in every row).

A simplified example if this scenario would be something as follows:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div><asp:Button ID="ButtonAdd" runat="server" Text="Add User Control" OnClick="ButtonAdd_OnClick" /></div>
        <div id="divContent" runat="server"></div>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <div><asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_OnClick" /></div>
    </ContentTemplate>
</asp:UpdatePanel>

And:

protected void ButtonAdd_OnClick(object sender, EventArgs e)
{
    MyUserControl uc = Page.LoadControl("MyUserControl.ascx") as MyUserControl;
    divContent.Controls.Add(uc);
}

protected void ButtonSave_OnClick(object sender, EventArgs e)
{
    // Hopefully, get controls from within the user control's grid and save their input
}

The problem is that after the save button is clicked, the user control is gone. That’s understandable and I have no problem creating and adding it again – but I do want to access the user input and save it. How can I do that?

  • 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-25T17:28:10+00:00Added an answer on May 25, 2026 at 5:28 pm

    If you want to add controls programatically then choose Page_Load (more preferred) or Page_Init event. You can solve your problem by adding control “statically” (design time) with visible=false and later you may turn on its visibility.

    In case you want stick with current approach as in your post, you have to use a trick.

    MyUserControl uc;
    
    protected void Page_Load()
    {
       if(ViewState["isAdd"]!=null)
        {
           AddControl();
        }
    }
    
    void AddControl()
    {
        uc = Page.LoadControl("MyUserControl.ascx") as MyUserControl;
        divContent.Controls.Add(uc);
    }
    
    protected void ButtonAdd_OnClick(object sender, EventArgs e)
    {
        if(ViewState["isAdd"]==null)
            AddControl();
        ViewState["isAdd"]="yes";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a User Control (an .ascx file) which is being dynamically inserting
I have a ASPX Page that contains several user controls, which are loaded dynamically
I have a user control which takes a Func which it then gives to
I have developed a user-control which gets bound to an id-field and then enables
I have a nested user control which appears on every single page. It contains
I have a page with a user control which gets some data updated via
Have a page that adds controls dynamically. Control state is being retrieved from database
I have user control on a ASP.NET web page, which contains a GridView and
Within a form I have a user control for each field being returned. The
I have an aspx page that dynamically loads user controls: there is an UpdatePanel

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.