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

The Archive Base Latest Questions

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

I have my own Control1 which is dynamically added as child control to Control2

  • 0

I have my own Control1 which is dynamically added as child control to Control2 which implements INamingContainer in CreateChildControls() of control2.

Control1 itself implements IPostBackEventHandler. But RaisePostBackEvent() method is never called on Control1, despite I do call postback method from JavaScript.

And yes, there are other controls which implement IPostBackEventHandler interface on the page.

What did I miss?

What could cause the issue?

UPDATE: Control1 is always created exactly the same way and assigned exactly the same ID in Control2

it looks like this in Control2:

protected override void CreateChildControls()
{
  if(!this.DesignMode)
  {
    Control1 c = new Control1();
    c.ID = "FIXED_ID";
  }
  base.CreateChildControls();
}

UPDATE2:
Control1:

public class Control1: Control, IPostBackEventHandler
{
...
    protected virtual void RaisePostBackEvent(string eventArgument)
    {
              if(!String.IsNullOrEmpty(eventArgument))
              {
                  // Some other code
              }
    }       
}

if I add line

Page.RegisterRequiresRaiseEvent(c);

In CreateChildControls() in Control2 then this method is being called but always with null eventArgument.

UPDATE3:

In JavaScript on some onClick event I do the following:

__doPostBack(Control1.UniqueID,'commandId=MyCommand');

where Control1.UniqueID is of course substituted with real uniqueID during rendering. I checked, this script is being called.

  • 1 1 Answer
  • 2 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-13T17:28:53+00:00Added an answer on May 13, 2026 at 5:28 pm

    Can you show us the source code of first control? Anyway there is a simple example.

    public class TestControl2 : CompositeControl
    {
    
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
    
            if (!DesignMode)
                this.Controls.Add(new TestControl());
        }
    
    }
    

    public class TestControl : WebControl, IPostBackEventHandler
    {
    
        public TestControl() : base(HtmlTextWriterTag.Input) { }
    
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
    
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
            writer.AddAttribute(HtmlTextWriterAttribute.Name, base.UniqueID);
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, null));
            writer.AddAttribute(HtmlTextWriterAttribute.Value, "Submit Query");
        }
    
        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        {
            // Raise post back event
        }
    
    }
    

    Edit

    1. Why you are generating the post back script out of the control and manually? You have to use Page.ClientScript.GetPostBackEventReference method. It generates and includes some necessary inline and embedded scripts to the page.

    2. Why you are deriving your class from Control? It’s good for those controls which don’t have any user interface.

    From MSDN

    This is the primary class that you
    derive from when you develop custom
    ASP.NET server controls. Control does
    not have any user interface (UI)
    specific features. If you are
    authoring a control that does not have
    a UI, or combines other controls that
    render their own UI, derive from
    Control. If you are authoring a
    control that does have a UI, derive
    from WebControl or any control in the
    System.Web.UI.WebControls namespace
    that provides an appropriate starting
    point for your custom control.

    You have to derive your control from WebControl class as follows.

    public class TestCtl : WebControl, IPostBackEventHandler
    {
    
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            // Add onclick event.
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "Arguments"));
        }
    
        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        {
            throw new NotImplementedException();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my own control which contains TextBox control as a child control.
I have my own control, derived from TCustomPanel . It has a child (
I have own component which works in my testing winform app good but when
I have two problems with an own user control which uses bitmaps: It flickers
So the problem is the following : i do have own user control. which
I have my own control which derives from StackPanel. This control contains two other
I have my own custom control derived from System.Windows.Forms.TreeView which is present on the
I am trying to make my own user control and have almost finished it,
I'm trying to hide window after its startup. I have own window-class which is
I have my own installer program which I use to install several applications I

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.