Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, you need your custom controls to be a part of the page tree. In this case ASP.NET will be able to find them and include all required scripts (if any). You don't need to override <code>RenderContents</code>. Simply add your drop-down list as well as the textbox to the <code>Controls</code> collection.</p> <p>Second, please read the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.createchildcontrols.aspx" rel="nofollow">API reference</a> for <code>CreateChildControls</code>. There is comment at the bottom of the page that states:</p> <blockquote> <p>Do not override <code>CreateChildControls</code>!</p> <p>You will run into a world of hurt, <strong>especially when it comes to subscribing to child control events</strong>! Instead, create a private method called, <code>CreateCustomChildControls</code>. Build your control tree there. Simply override <code>OnInit</code> and call <code>CreateCustomChildControls</code> from there.</p> </blockquote> <p>So in your case the code will look like the following:</p> <pre><code>[ToolboxData("&lt;{0}:ServerControl2 runat=server&gt;&lt;/{0}:ServerControl2&gt;")] public class ServerControl1 : WebControl { protected DropDownList drplist; protected TextBox tb; protected override void OnInit(EventArgs e) { base.OnInit(e); CreateCustomChildControls(); } private void CreateCustomChildControls() { drplist = new DropDownList() { AutoPostBack = true }; drplist.Items.Add("a"); drplist.Items.Add("b"); drplist.Items.Add("c"); drplist.Items.Add("d"); drplist.SelectedIndexChanged += new EventHandler(drplist_SelectedIndexChanged); tb = new TextBox(); base.Controls.Add(drplist); base.Controls.Add(tb); } void drplist_SelectedIndexChanged(object sender, EventArgs e) { tb.Text = "even fired"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload