New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Back Button and SelectedValue

PROBLEM

Steps to reproduce the problem:

  1. Select a combo item

  2. Use Response.Redirect or Server.Transfer to go to another page

  3. Click on the Back button of the browser

The combobox shows the correct text, but the SelectedValue property is incorrect (the SelectedItem is lost).

WORKAROUND

First, add a hidden field to the page that will hold the selected value of the combobox:

HTML
	<input type="hidden" id="RadComboBox1Value" value="" />

After that, subscribe to the OnClientSelectedIndexChanged event and update that hidden field:

JavaScript
	function onSelectedIndexChanged(sender, eventArgs) {
		$get("RadComboBox1Value").value = eventArgs.get_item().get_value();
	}

In the end, on pageLoad() check for the value of the hidden field. If it is not empty - find the appropriate combo item and select it:

JavaScript
function pageLoad() {
	var savedValue = $get("RadComboBox1Value").value;
	var combo = $find('<%= RadComboBox1.ClientID %>');

	if (savedValue != "" && combo.findItemByValue(savedValue)) {
		combo.findItemByValue(savedValue).select();
	}
	````

Here is the final code:

````ASP.NET
<telerik:RadComboBox RenderMode="Lightweight" ID="RadComboBox1"
	runat="server"
	OnClientSelectedIndexChanged="onSelectedIndexChanged">
	<Items>
		<telerik:RadComboBoxItem runat="server" Text="Red" Value="red" />
		<telerik:RadComboBoxItem runat="server" Text="Blue" Value="blue" />
		<telerik:RadComboBoxItem runat="server" Text="Green" Value="Green" />
	</Items>
</telerik:RadComboBox>

<input type="hidden" id="RadComboBox1Value" value="" />
<asp:Button ID="Button1" runat="server" Text="Button that Redirects" />
JavaScript
	function pageLoad() {
		var savedValue = $get("RadComboBox1Value").value;
		var combo = $find('<%= RadComboBox1.ClientID %>');

		if (savedValue != "" && combo.findItemByValue(savedValue)) {
			combo.findItemByValue(savedValue).select();
		}
	}

	function onSelectedIndexChanged(sender, eventArgs) {
		$get("RadComboBox1Value").value = eventArgs.get_item().get_value();
	}
Not finding the help you need?
Contact Support