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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:13:58+00:00 2026-06-12T07:13:58+00:00

I’m trying to create a templated composite control that would work in a similar

  • 0

I’m trying to create a templated composite control that would work in a similar fashion as the “PasswordRecovery” control of ASP.Net.

By that, I mean that the user can define its own template but, by using pre-defined controls ID, it defines which field is, say the e-mail address, and which button is the one to send the e-mail.

I’ve tried to look at the documentation for templated web server controls, but I can’t find anything talking about adding a behavior to those controls.

Alternatively, is there a way to change the behavior of the PasswordRecovery completely? I would like to send an e-mail with a one-time URL to change the password instead of the common behavior of that control.

  • 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-12T07:13:59+00:00Added an answer on June 12, 2026 at 7:13 am

    I answered a related question:

    https://stackoverflow.com/a/11700540/1268570

    But in this answer I will go deeper.

    I will post a templated server control with design support and with custom behavior:

    Container code

    [ToolboxItem(false)]
    public class TemplatedServerAddressContainer : WebControl, INamingContainer
    {
        public string Address { get; protected set; }
    
        public TemplatedServerAddressContainer(string address)
        {
            this.Address = address;
        }
    }
    
    • The above control will be in charge to keep the data you want to send to the control as OUTPUT. That will be the control you will instantiate your template in

    Server Control

    [DefaultProperty("Address")]
    [ToolboxItem(true)]
    [ToolboxData("<{0}:TemplatedServerAddressControl runate=server></{0}:TemplatedServerAddressControl>")]
    [Designer(typeof(TemplatedServerAddressDesigner))]
    //[ToolboxBitmap(typeof(TemplatedServerAddressControl), "")]
    [Description("My templated server control")]
    [ParseChildren(true)]
    public class TemplatedServerAddressControl : WebControl
    {
        private TemplatedServerAddressContainer addressContainer;
    
        [Bindable(true)]
        [Localizable(true)]
        [DefaultValue(null)]
        [Description("The custom address")]
        [Category("Apperance")]
        [Browsable(true)]
        public string Address
        {
            get
            {
                return (this.ViewState["Address"] ?? string.Empty).ToString();
            }
            set
            {
                this.ViewState["Address"] = value;
            }
        }
    
        [Browsable(false)]
        [DefaultValue(null)]
        [Description("Address template")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [TemplateContainer(typeof(TemplatedServerAddressContainer))]
        [TemplateInstance(TemplateInstance.Multiple)]
        public ITemplate AddressTemplate { get; set; }
    
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public TemplatedServerAddressContainer AddressContainer
        {
            get
            {
                this.EnsureChildControls();
    
                return this.addressContainer;
            }
            internal set
            {
                this.addressContainer = value;
            }
        }
    
        public override ControlCollection Controls
        {
            get
            {
                this.EnsureChildControls();
    
                return base.Controls;
            }
        }
    
        public override void DataBind()
        {
            this.CreateChildControls();
            this.ChildControlsCreated = true;
    
            base.DataBind();
        }
    
        protected override void CreateChildControls()
        {
            this.Controls.Clear();
    
            if (this.AddressTemplate != null)
            {
                this.addressContainer = new TemplatedServerAddressContainer(this.Address);
    
                this.AddressTemplate.InstantiateIn(this.addressContainer);
                this.Controls.Add(this.addressContainer);
            }
        }
    
        protected override bool OnBubbleEvent(object source, EventArgs args)
        {
            if (args is CommandEventArgs)
            {
                var commandArgs = args as CommandEventArgs;
    
                switch (commandArgs.CommandName)
                {
                    case "DoSomething":
                        // place here your custom logic
                        this.Page.Response.Write("Command bubbled");
                        return true;
                }
            }
    
            return base.OnBubbleEvent(source, args);
        }
    }
    
    • The public string Address property is used as control INPUT, you can create all the input properties you need in order to execute your task.

    • public ITemplate AddressTemplate { get; set; } This represents the template of your control. The name you give to this property will be the name used in the page’s markup as the name of your template

    • public TemplatedServerAddressContainer AddressContainer This property is just for designer support

    • In order to create correctly the child controls you need to override the following methods and properties: Controls, DataBind and CreateChildControls

    • Overriding the OnBubbleEvent, you will be able to react to specific events coming from the control.

    Designer support

    public class TemplatedServerAddressDesigner : ControlDesigner
    {
        private TemplatedServerAddressControl controlInstance;
    
        public override void Initialize(IComponent component)
        {
            this.controlInstance = (TemplatedServerAddressControl)component;
    
            base.Initialize(component);
        }
    
        public override string GetDesignTimeHtml()
        {
            var sw = new StringWriter();
            var htmlWriter = new HtmlTextWriter(sw);
            var controlTemplate = this.controlInstance.AddressTemplate;
    
            if (controlTemplate != null)
            {
                this.controlInstance.AddressContainer = new TemplatedServerAddressContainer(
                    this.controlInstance.Address
                    );
                controlTemplate.InstantiateIn(this.controlInstance.AddressContainer);
    
                this.controlInstance.DataBind();
    
                this.controlInstance.RenderControl(htmlWriter);
            }
    
            return sw.ToString();
        }
    }
    

    ASPX markup

    <%@ Register Assembly="Msts" Namespace="Msts.Topics.Chapter07___Server_Controls.Lesson02___Server_Controls" TagPrefix="address" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <address:TemplatedServerAddressControl runat="server" ID="addressControl1">
            <AddressTemplate>
                <b>
                    Address:
                </b>
                <u>
                    <asp:Literal Text="<%# Container.Address %>" runat="server" />
                </u>
                <asp:Button Text="text" runat="server" OnClick="Unnamed_Click" ID="myButton" />
                <br />
                <asp:Button Text="Command bubbled" runat="server" CommandName="DoSomething" OnClick="Unnamed2_Click1" />
            </AddressTemplate>
        </address:TemplatedServerAddressControl>
    </asp:Content>
    

    ASPX code behind

    public partial class TemplatedServerAddress : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.addressControl1.Address = "Super Cool";
            this.DataBind();
        }
    
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            this.Response.Write("From custom button" + DateTime.Now.ToString());
        }
    
        protected void Unnamed2_Click1(object sender, EventArgs e)
        {
            this.Response.Write("From command button " + DateTime.Now.ToString());
        }
    }
    
    • Notice how you can set control’s properties without problems in the correct event: this.addressControl1.Address = "Super Cool";

    • Notice how your control can handle custom events this.Response.Write("From custom button" + DateTime.Now.ToString());

    • And finally, to indicate to your control that you want to perform something, just create a button with the command name exposed by your control like this: <asp:Button Text="Command bubbled" runat="server" CommandName="DoSomething" OnClick="Unnamed2_Click1" /> optionally, your button can contain an event handler that will be handled prior to bubbling the event.

    I uploaded this code sample completely functional to my GitHub for reference

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.