I have 3 combo boxes. When an item is selected in the first, the second is populated. When an item in the second is selected the third is populated. This all works fine until the page is posted back where the SelectedValues for the second and third combos have not changed from what they were initally set to when the page is loaded.
The 3 combos and client side script look like:
<telerik:RadComboBox runat="server" ID="cboCopyFromTariff" Width="250" OnClientSelectedIndexChanged="cboCopyFromTariff_ClientSelectedIndexChanged" />
<telerik:RadComboBox runat="server" ID="cboCopyFromVersion" Width="250" OnClientSelectedIndexChanged="cboCopyFromVersion_ClientSelectedIndexChanged" OnClientItemsRequested="cboCopyFromVersion_ClientItemsRequested"/>
<telerik:RadComboBox runat="server" ID="cboCopyFromTable" Width="250" OnClientItemsRequested="cboCopyFromTable_ClientItemsRequested" />
function cboCopyFromVersion_ClientItemsRequested(sender, eventArgs) {
var items = sender.get_items();
if (items.get_count() > 0)
items.getItem(0).select();
}
function cboCopyFromTable_ClientItemsRequested(sender, eventArgs) {
var items = sender.get_items();
if (items.get_count() > 0)
items.getItem(0).select();
}
And the server side code looks like this:
private void cboCopyFromVersion_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
int tariffId = 0;
int.TryParse(e.Text, out tariffId);
LoadCopyFromVersions(tariffId);
}
private void cboCopyFromTable_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
int tariffVersionId = 0;
int.TryParse(e.Text, out tariffVersionId);
LoadCopyFromTables(tariffVersionId);
}
private void LoadCopyFromVersions(int tariffId)
{
cboCopyFromVersion.Items.Clear();
if (tariffId > 0)
{
var versions =
from v in this.DataContext.TariffVersionSet
where v.Tariff.TariffId == tariffId
orderby v.StartDate descending
select v;
cboCopyFromVersion.Items.Clear();
cboCopyFromVersion.DataValueField = "TariffVersionId";
cboCopyFromVersion.DataTextField = "Description";
cboCopyFromVersion.DataSource = versions.ToList();
cboCopyFromVersion.DataBind();
//Default to the TariffVersion passed
if (cboCopyFromVersion.Items.Count > 0)
{
int TariffVersionId = this.TariffVersion.TariffVersionId;
if (cboCopyFromVersion.Items.FindItemByValue(TariffVersionId.ToString()) != null)
cboCopyFromVersion.SelectedValue = TariffVersionId.ToString();
else
cboCopyFromVersion.SelectedIndex = 0;
LoadCopyFromTables(int.Parse(cboCopyFromVersion.SelectedValue));
}
else
LoadCopyFromTables(0);
}
else
LoadCopyFromTables(0);
}
private void LoadCopyFromTables(int tariffVersionId)
{
cboCopyFromTable.Items.Clear();
if (tariffVersionId > 0)
{
var tables =
from tt in this.DataContext.TariffTableSet
where tt.TariffVersion.TariffVersionId == tariffVersionId
orderby tt.Description descending
select tt;
cboCopyFromTable.DataValueField = "TariffTableId";
cboCopyFromTable.DataTextField = "Description";
cboCopyFromTable.DataSource = tables.ToList();
cboCopyFromTable.DataBind();
//Default to the latest TariffVersion for the selected Tariff
if (cboCopyFromTable.Items.Count > 0)
cboCopyFromTable.SelectedIndex = 0;
}
}
The problem occurs in the Save button's click handler:
protected void btnSave_Click(object sender, EventArgs e)
{
EF.TariffTable table;
if (optCopyTable.Checked && cboCopyFromTable.SelectedIndex > -1)
table = CopyTariffTable(int.Parse(cboCopyFromTable.SelectedValue));
else
table = CreateEmptyTariffTable();
}
When a new item is selected in the first combo the second combo correctly displays the first item filtered by the first's selection. And the third combo correctly shows the first item correctly filtered by the second.
However in the Save button handler the SelectedValue of the third combo (cboCopyFromTable) does not match what is displayed as selected.
I have read similar forum posts for previous versions of RadCombo and they suggest using the "Value" property instead of "SelectedValue", but the ASP.NET AJAX version doesn't have this property.
The help file article ms-help://telerik.aspnetajax.radcontrols.2008.Q2/telerik.aspnetajax.radcombobox.2008.Q2/load-on-demand-additional-attributes.html suggests a way of linking two combos together but it depends on EnableLoadOnDemand to be true. This is not suitable for my solution as there are few items in each combo and I don't want the user to be able to type in the box.
Can anyone suggest how to fix this so that the server side code is aware of the changes made during the AJAX callbacks?
Many thanks,
Jason Steele