I've run into a problem using the asp.net ajax RadComboBox that is dynamically added to the page, which is caused by it losing its value if more than one postback occurs.
I select an item in the combobox and then trigger a postback. After the first postback the initially selected value is still selected, but after a second postback it is not. The old style RadComboBox and the built in DropDownList both retain their selected value.
Here's a simple test example that shows the problem. The aspx simply contains a repeater with a placeholder inside it.
In the ItemDataBound event handler the combo boxes are created and added to the placeholder. If I select Item 2 in each combo box and then click the button twice then at the end the first two combo boxes still have Item 2 selected but the asp.net ajax RadComboBox has reverted to Item 1.
I select an item in the combobox and then trigger a postback. After the first postback the initially selected value is still selected, but after a second postback it is not. The old style RadComboBox and the built in DropDownList both retain their selected value.
Here's a simple test example that shows the problem. The aspx simply contains a repeater with a placeholder inside it.
<asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager> |
<asp:Repeater ID="repTest" runat="server"> |
<ItemTemplate> |
<div> |
<asp:PlaceHolder ID="plcTest" runat="server"></asp:PlaceHolder> |
</div> |
</ItemTemplate> |
</asp:Repeater> |
<asp:Button ID="btnTest" runat="server" Text="PostBack" /> |
In the ItemDataBound event handler the combo boxes are created and added to the placeholder. If I select Item 2 in each combo box and then click the button twice then at the end the first two combo boxes still have Item 2 selected but the asp.net ajax RadComboBox has reverted to Item 1.
protected void Page_Load(object sender, EventArgs e) |
{ |
repTest.DataSource = new int[] { 1, 2, 3 }; |
repTest.DataBind(); |
} |
protected override void OnInit(EventArgs e) |
{ |
base.OnInit(e); |
repTest.ItemDataBound += new RepeaterItemEventHandler(repTest_ItemDataBound); |
} |
private void repTest_ItemDataBound(object sender, RepeaterItemEventArgs e) |
{ |
PlaceHolder plcTest = (PlaceHolder)e.Item.FindControl("plcTest"); |
switch ((int)e.Item.DataItem) |
{ |
case 1: |
DropDownList cbo1 = new DropDownList(); |
cbo1.ID = "cbo1"; |
cbo1.DataSource = GetComboData(); |
cbo1.DataBind(); |
plcTest.Controls.Add(cbo1); |
break; |
case 2: |
Telerik.WebControls.RadComboBox cbo2 = new Telerik.WebControls.RadComboBox(); |
cbo2.ID = "cbo2"; |
cbo2.DataSource = GetComboData(); |
cbo2.DataBind(); |
plcTest.Controls.Add(cbo2); |
break; |
case 3: |
Telerik.Web.UI.RadComboBox cbo3 = new Telerik.Web.UI.RadComboBox(); |
cbo3.ID = "cbo3"; |
cbo3.DataSource = GetComboData(); |
cbo3.DataBind(); |
plcTest.Controls.Add(cbo3); |
break; |
} |
} |
private string[] GetComboData() |
{ |
return "Item 1;Item 2;Item 3".Split(';'); |
} |