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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:22:46+00:00 2026-06-08T16:22:46+00:00

I am creating a server control that will sit in a aspx page. When

  • 0

I am creating a server control that will sit in a aspx page. When the user selects a menu option, html controls (selects, inputs, etc) will have be added dynamically. I can do it using a user control, but I’m not sure how to go about it in a server control.

Can anyone tell me how I can add dynamic html into the control after it’s already sitting in a page?

  • 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-08T16:22:47+00:00Added an answer on June 8, 2026 at 4:22 pm

    Since you are planning to add several controls as the output of your server control, you should consider inheriting from CompositeControl, this control is designed to work with several constituent controls, minimizing the code needed to do common things like keeping state and handling constituent control events

    You need to override the CreateChildControls to add child controls. At the end of this method you should use this.ChildControlsCreated = true; to specify if the child controls were created, this is necessary because the CreateChildControls is called several times during the ASP.Net page life-cycle

    You need to apply the same rules that you would typically apply to any server control, for example implement the INamingContainer interface to ensure that child controls will have a unique client ID

    This is a simple example:

    [DefaultProperty("UserText")]
    [ToolboxData(@"<{0}:UserPassword runat=server UserText="""" PasswordText="""" />")]
    public class UserPassword : CompositeControl
    {
        public event EventHandler Submitted = delegate { };
    
        [Bindable(true)]
        [Category("Appearance")]
        [Description("User text")]
        [DefaultValue("")]
        [Localizable(true)]
        public string UserText
        {
            get
            {
                var t = this.FindControl("Username") as TextBox;
                return t.Text;
            }
            set
            {
                var t = this.FindControl("Username") as TextBox;
                t.Text = value;
            }
        }
    
        [Bindable(true)]
        [Category("Appearance")]
        [Description("Password text")]
        [DefaultValue("")]
        [Localizable(true)]
        public string PasswordText
        {
            get
            {
                var t = this.FindControl("Password") as TextBox;
                return t.Text;
            }
            set
            {
                var t = this.FindControl("Password") as TextBox;
                t.Text = value;
            }
        }
    
        protected override void CreateChildControls()
        {
            var p = new Panel { Width= new Unit(200), BackColor = Color.Silver };
            var ul = new Label { Text = "Username: " };
            var u = new TextBox { ID = "Username" };
            var pal = new Label { Text = "Password: " };
            var pa = new TextBox { ID = "Password", TextMode = TextBoxMode.Password };
            var l = new Literal { Text = "<br />" };
            var b = new Button { Text = "Log in" };
    
            b.Click += (x, y) => this.Submitted(x, y);
    
            p.Controls.Add(ul);
            p.Controls.Add(u);
            p.Controls.Add(l);
            p.Controls.Add(pal);
            p.Controls.Add(pa);
            p.Controls.Add(l);
            p.Controls.Add(l);
            p.Controls.Add(b);
    
            this.Controls.Add(p);
            this.ChildControlsCreated = true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating user controls that i will put into an update panel and make
Greetings! I'm creating a User Control that will display data in a GridView control.
I have a user control that will render a textbox or file upload. I
I have created four ASP.NET Server controls that will inject a lot of JavaScript
I am creating a custom ASP.NET AJAX server control in which multiple instances of
Creating a server-side socket will fail if I'm trying to use the same port
I'm creating a server/client solution with custom user logins (not WindowsIdentity). I need a
I use ReportViewer web server control on a web page. The goal is to
I'm creating a chat widget that will be dropped into CommunityServer. The widget works
I am creating a custom server control to generate button elements with specific markup

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.