Dropdownlist SelectedIndexChanged firing on every postback
<p>I am dynamically adding a custom user control to an update panel.  My user control contains two dropdownlists and a textbox.  When a control outside of the update panel triggers a postsback, I am re-adding the user control to the update panel.</p>

<p>The problem is...on postback when I re-add the user controls, it's firing the "SelectedIndexChanged" event of the dropdownlists inside the user control.  Even if the selectedindex did not change since the last postback.</p>

<p>Any ideas?</p>

<p>I can post the code if necessary, but there's quite a bit in this particular scenario.</p>

<p>Thanks in advance!</p>

<p><em>EDIT...CODE ADDED BELOW</em></p>

<p>*<strong>.ASCX</strong></p>

<pre><code>&lt;asp:DropDownList ID="ddlColumns" OnSelectedIndexChanged="ddlColumns_SelectedChanged" AppendDataBoundItems="true" AutoPostBack="true" runat="server"&gt;
</code></pre>

<p>*<strong>.ASCX.CS</strong></p>

<pre><code>List&lt;dataColumnSpecs&gt; dataColumns = new List&lt;dataColumnSpecs&gt;();

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        fillDDLColumns();
    }        
}

public void fillDataColumnsList()
{
    dataColumns.Clear();
    //COMMON GETDATATABLE RETURNS A DATA TABLE POPULATED WITH THE RESULTS FROM THE STORED PROC COMMAND
    DataTable dt = common.getDataTable(storedProcs.SELECT_COLUMNS, new List&lt;SqlParameter&gt;());
    foreach (DataRow dr in dt.Rows)
    {
        dataColumns.Add(new dataColumnSpecs(dr["columnName"].ToString(), dr["friendlyName"].ToString(), dr["dataType"].ToString(), (int)dr["dataSize"]));
    }
}

public void fillDDLColumns()
{
    fillDataColumnsList();
    ddlColumns.Items.Clear();
    foreach (dataColumnSpecs dcs in dataColumns) 
    { 
        ListItem li = new ListItem(); 
        li.Text = dcs.friendlyName; 
        li.Value = dcs.columnName; 
        ddlColumns.Items.Add(li);
    }
    ddlColumns.Items.Insert(0, new ListItem(" -SELECT A COLUMN- ", ""));
    ddlColumns.DataBind();  
}

protected void ddlColumns_SelectedChanged(object sender, EventArgs e)
{
    //THIS CODE IS BEING FIRED WHEN A BUTTON ON THE PARENT *.ASPX IS CLICKED
}
</code></pre>

<p>*<strong>.ASPX</strong></p>

<pre><code>&lt;asp:UpdatePanel ID="upControls" runat="server"&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:Button ID="btnAddControl" runat="server" Text="+" OnClick="btnAddControl_Click" /&gt;
    &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;
&lt;asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" ValidationGroup="vgGo" /&gt;
&lt;asp:GridView...
</code></pre>

<p>*<strong>.ASPX.CS</strong></p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        uc_Counter = 0;
        addControl();
        gridview_DataBind();
    }
    else
    {
        reloadControls();
    }
}

protected void btnGo_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        //THIS BUTTON CLICK IS WHAT'S TRIGGERING THE 
        //SELECTEDINDEXCHANGED EVENT TO FIRE ON MY *.ASCX
        gridview_DataBind();
    }   
}

private void reloadControls()
{
    int count = this.uc_Counter;

    for (int i = 0; i &lt; count; i++)
    {
        Control myUserControl = Page.LoadControl("~/Controls/myUserControl.ascx");
        myUserControl.ID = "scID_" + i;
        upControls.ContentTemplateContainer.Controls.AddAt(i, myUserControl);
        ((customUserControl)myUserControl).fillDDLColumns();
    }
}

private void addControl()
{
    Control myUserControl = Page.LoadControl("~/Controls/myUserControl.ascx");
    myUserControl.ID = "scID_" + uc_Counter.ToString();
    upControls.ContentTemplateContainer.Controls.AddAt(upControls.ContentTemplateContainer.Controls.IndexOf(btnAddControl), myUserControl);            
    //((customUserControl)myUserControl).fillDDLColumns();
    this.uc_Counter++;
}

protected int uc_Counter
{
    get { return (int)ViewState["uc_Counter"]; }
    set { ViewState["uc_Counter"] = value; }
}
</code></pre>
