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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:43:37+00:00 2026-06-04T23:43:37+00:00

In my main .aspx page I have a placeholder in which it get registered

  • 0

In my main .aspx page I have a placeholder in which it get registered dynamically two types of user controls.

case "1":
   var control = (ControlType)LoadControl("~/PathToControl.ascx");
   control.Property = value;
   control.Initialize();
   placeholder.controls.add(control);
break;
case "2":
   var control1 = (ControlType)LoadControl("~/PathToControl1.ascx");
   control1.Property = value;
   control1.Initialize();
   placeholder.controls.add(control1);
break;

Each control has some user controls.

Now, in the main page I have a submit button and I want to get the values of each user coltrol from the above custom control.
I tried to get the controls of the placeholder but the placeholder after the postback is empty.

if(placeholder.Controls.count>0){
  var userControl = ((UserControlType)placeholder.Controls[0]);
  var controlName = userControl.FindControl("ControlName") as TextBox;
}

I tried also to build the custom controls on page_init but I still can’t get the user controls.

Does anyone know how can I achieve this?

SOLUTION

The dynamic user controls must be set in Init Event on each and every visit.

For more information http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic4

  • 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-04T23:43:38+00:00Added an answer on June 4, 2026 at 11:43 pm

    The controls must be registered in Init event

    protected override void OnInit(EventArgs e) {
       case "1":
            var control = (ControlType)LoadControl("~/PathToControl.ascx");
            control.ID = "controlID";
            placeholder.controls.add(control);
      break;
      case "2":
          var control1 = (ControlType)LoadControl("~/PathToControl1.ascx");
          control.ID = "controlID_1";
          placeholder.controls.add(control1);
       break;
    base.OnInit(e);
    }
    

    set whatever properties you want after the Init

    case "1":
      var control = (ControlType)placeholder.findControl("ControlID");
      control.Property = value;
     control.Initialize();
    break;
    case "2":
     var control1 = (ControlType)placeholder.findControl("ControlID_1");
     control1.Property = value;
     control1.Initialize();
    break;
    

    After page’s post back

    void LoadControls(){
       case "1":
        var control = (ControlType)placeholder.findControl("ControlID");
        var txtControl =  control.FindControl("controlName") as TextBox;
       break;
       case "2":
        var control1 = (ControlType)placeholder.findControl("ControlID_1");
        var txtControl_1 =  control1.FindControl("controlName") as TextBox;
       break;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main aspx page in which there is a list of items.
I have an aspx page with 5 user controls. I have $(document).ready() in each
In my project i have a main aspx page. On that page i create
I have problem passing a variable from a main page containing a user control
in my job (intranet)- I have an aspx page which has many Iframes (
I have a main page (Home.aspx) and on selecting a link from the menu
I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is
I have a dropdownlist in aspx page. I have a gridview in user control.I
In my asp .net C# project I have a page defualt.aspx on which I
I have a Main.aspx page and a Sub.aspx page. The Sub.aspx page resides in

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.