Server Control with dropdown and button, and trigger own event
<p>i have a C# server control which contains one button and one dropdown
i want to response.write the dropdown selectedindex to the page while the button click
and i dont want to make the event handler on page level (aspx), but i want to code it inside the control and compile as dll</p>

<p>my flow is :
construct the button and dropdown, which the control class is load
override CreateChildControls to add the button into the server control and bind the click event to it
override the RenderControl to add the dropdown to a table, and then render the button</p>

<p>finally i found that the button event can be click, but it just cant get the dropdown selected item, when i select the second one</p>

<p>here is the code :</p>

<pre><code>    public class ServerControl1  : WebControl, INamingContainer
    {       
            public ServerControl1()
            {
                _oBtn = new Button();
                _oBtn.ID = "btn";
                _oBtn.Text = "Click Me";
                _oBtn.Click += new EventHandler(_oBtn_Click);
                _ddl = new DropDownList();
                _ddl.ID = "ddl";
                _ddl.Items.add(new ListItem("xxxxxxxx", "xxxxxxxx"))
                _ddl.Items.add(new ListItem("yyyyyyy", "yyyyyyy"))
            }

            protected override void CreateChildControls()
            {
                this.Controls.Add(_oBtn);
                base.CreateChildControls();
            }

             public override void RenderControl(HtmlTextWriter writer)
            {
                AddAttributesToRender(writer);
                Table m_oTable = new Table();
                TableRow m_oRow;
                TableCell m_oCell;
                m_oCell = new TableCell();
                m_oCell.Controls.Add(_ddl);
                m_oRow.Cells.Add(m_oCell);
                m_oTable.Rows.Add(m_oRow);
                m_oTable.RenderControl(writer);
                _oBtn.RenderControl(writer);
            }

            protected void _oBtn_Click(object sender, EventArgs e)
            {
                if (_ddl.SelectedIndex != 0)
                {
                    Page.Response.Redirect(Url + "&amp;f0=" + _ddl.SelectedIndex);
                }
                else
                {
                    Page.Response.Write("nonononon");
                }
            }
    }
</code></pre>
