问题
I have two comboboxes, first one triggers updatepanel that updates second one:
protected void cb1_SelectedIndexChanged(object sender, EventArgs e)
{
cb2.DataSource = DT1;
cb2.DataBind();
}
Problem is, when I click button, all values are ok, except one in UpdatePanel, so updatepanel somehow resets selected index on child controls.
Any idea how to fix this?
I know about sessions, but I don't know on what step to assign value of cb2 to session.
Thanks.
Update, aspx
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False"
UpdateMode="Conditional">
<dx:ASPxComboBox ID="cb2" runat="server" Height="22px" ValueField="ID"
ValueType="System.Int32" Width="170px">
<Columns>
<dx:ListBoxColumn Caption="ID" FieldName="ID" Visible="False" />
<dx:ListBoxColumn Caption="City" FieldName="City" />
</Columns>
</dx:ASPxComboBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="cb1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
回答1:
A couple of things here: you have ChildrenAsTriggers="False"
, but yet you have an async postback trigeer for a child control: 'cb2'. I think you should remove the ChildrenAsTriggers="False"
property ("true" is default value) and you probably meant to have the ansync postback trigeer set to the `cb1' control like below:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<dx:ASPxComboBox ID="cb2" runat="server" Height="22px" ValueField="ID"
ValueType="System.Int32" Width="170px">
<Columns>
<dx:ListBoxColumn Caption="ID" FieldName="ID" Visible="False" />
<dx:ListBoxColumn Caption="City" FieldName="City" />
</Columns>
</dx:ASPxComboBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cb1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Also I think your original code copied was missing the opening <ContentTemplate>
tag.
At this point your cb1 control's event `cb1_SelectedIndexChanged' should fire and be able to update the cb2 control's datasource in the UpdatePanel above.
来源:https://stackoverflow.com/questions/9911816/control-in-updatepanel-loses-value