I want to create multiple select dropdown on the server side. Is that possible and if that possible how? How can I write this code on the server- side?
<dx:ASPxDropDownEdit ClientInstanceName="checkComboBox" ID="ASPxDropDownEdit" runat="server" AnimationType="None" CssClass="otherItemTextBox" ItemStyle-CssClass="detailControl" Width="400px" Caption="<%$ Resources:tables, TabPageNameLabel %>" CaptionCellStyle-CssClass="otherItemLabel">
<DropDownWindowStyle BackColor="#EDEDED" />
<DropDownWindowTemplate>
<dx:ASPxListBox Width="100%" ID="ListBoxLookup" ClientInstanceName="checkListBox" SelectionMode="CheckColumn"
runat="server" Height="200" EnableSelectAll="true" EnableSynchronization="True" OnDataBound="ListBoxLookup_DataBound">
<FilteringSettings ShowSearchUI="true" />
<Border BorderStyle="None" />
<BorderBottom BorderStyle="Solid" BorderWidth="1px" BorderColor="#DCDCDC" />
<ClientSideEvents SelectedIndexChanged="updateText" Init="updateText" />
</dx:ASPxListBox>
<table style="width: 100%">
<tr>
<td style="padding: 4px">
<dx:ASPxButton ID="CloseButton" AutoPostBack="False" runat="server" Text="Close" Style="float: right">
<ClientSideEvents Click="function(s, e){ checkComboBox.HideDropDown(); }" />
<Image IconID="actions_close_16x16devav"></Image>
</dx:ASPxButton>
<dx:ASPxButton ID="DataSearchButton" AutoPostBack="true" runat="server" Text="Search" Style="float: right" OnClick="DataSearchButton_Click">
<Image IconID="actions_search_16x16devav"></Image>
</dx:ASPxButton>
</td>
</tr>
</table>
</DropDownWindowTemplate>
<ClientSideEvents TextChanged="synchronizeListBoxValues" DropDown="synchronizeListBoxValues" />
</dx:ASPxDropDownEdit>
2
Answers
If you are creating controls dynamically on the server-side then you need to make sure you re-create them for the postback. Otherwise, the viewstate will fail when you postback. Controls must be in the same position and with the same id on a postback as they were when they were originally written in the response.
For "Page" you need to re-create them during the OnInit
For controls dynamically created in a "WebUserControl", you must re-create them in the onLoad event.
Generally:
I recommend that you refer to the following article for instructions on how to create controls dynamically:
How to create controls dynamically
According to this article, once you have modified the entire controls hierarchy (i.e., added the control into the controls collection), it is necessary to restore this control with the same settings during the Page_Init stage.
Example — How to create controls dynamically