I think this is an asp.net page life cycle question, but none the less, i can't quite figure it out.
I have a drop down list in an update panel that lists users and then shows details below it (update or delete). When the I click delete, the code behind goes and clears the ddl (to remove the deleted user), and then rebinds it. All fine. Somewhere between the end of the code behind and when the page updates, it then appends the list again.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.AppendDataBoundItems = true;
DropDownList1.Items.Insert(0, new ListItem("Select a User", "select"));
DropDownList1.SelectedValue = "select";
DropDownList1.DataSourceID = "srcUsers";
DropDownList1.DataBind();
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
DropDownList1.AppendDataBoundItems = false;
DropDownList1.DataSourceID = "srcUsers";
DropDownList1.DataBind();
DropDownList1.AppendDataBoundItems = true;
DropDownList1.Items.Insert(0, new ListItem("Select a User", "select"));
DropDownList1.SelectedValue = "select";
}//at this point, the quick watch shows the correct count for the ddl
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" Width="150" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Note: srcUsers
is a object data source
If I remove the ddl binding code from the button, then it doesn't update the ddl at all (with it in, it does it twice!)
Where is it binding the second time? Why isn't it binding if I remove the button code? How come I can't step through this in VS?