hi,

I have a web form that consists of several Radcombobox. The first combobox gets its list from a database.
After selecting a value from this combobox i would like it to update the text shown on the second Radcombobox. The autopostback is always resetting the value of the second Radcombobox to the first item in its predefined list.

How do I overcome this?

Dani AI

Generated

Short answer: the second RadComboBox is almost always being rebound during the page lifecycle (or before ViewState can restore its selection), so the autopostback from the first combo replaces whatever text/selection you expected. 's fix (only populate on the initial render) is the right root fix; was also correct that avoiding full postbacks or doing client-side updates removes the whole class of problems.

Server-side pattern that is reliable

  • Populate static lists only on the first time the page is rendered. Populate the dependent list inside the event handler for the first combobox change (ensure the first combobox posts back).
  • If something in your page forces the dependent combobox to be rebound every request (DataSource control, master page logic, etc.), capture the current value before the rebind and restore it right after — that prevents the visible text from jumping back to the default.

Example (preserve-and-restore approach)

string saved = RadComboBox2.SelectedValue;
RadComboBox2.DataSource = GetItemsFor(selectedState);
RadComboBox2.DataBind();
RadComboBox2.SelectedValue = saved;  // restore if still valid

Client-side / partial-update alternatives

  • If you want instant changes with no round-trip, preload the dependent lists (JSON or hidden data) and use the RadComboBox client API or plain JS to replace items/text on selection.
  • If you prefer server logic but want to avoid full-page reloads, use an UpdatePanel or Telerik RadAjax so only the dependent combobox is refreshed.

Quick troubleshooting checklist

  • Verify AutoPostBack on the first combobox is enabled.
  • Move unconditional DataBind calls out of the top of the page lifecycle.
  • Make sure ViewState for the combobox is enabled (or explicitly persist selection in a hidden field/session).
  • Put a breakpoint or trace where you bind the second combobox to confirm when and how often it runs.

This explains why the observed behavior happens and gives safe, practical ways to keep the second combobox showing the expected text after a selection in the first.

Recommended Answers

All 2 Replies

well if you want to change comboboxes items without having to postback , your gonna have to change them with javascript.

if you really do not want to rely on javascript , then you can manage your postbacks with querystring, Session variables , or even cookies but that would be overkill, Session would be fine.

Lets say Combobox1 is States and combo box 2 is Towns or whatever.
When user changes the selectedIndex of combo1 , save the new selectedIndex in a Session variable Session("state") , then on your page load check if postback is true and if it is, check if you have a value for Session("state"), if you do, load the proper items in combo2

alternatively with querystring simply redirect to the same page with "state=UserSelection" at the end of the link ("mypage.aspx?state=something") , and in your page load check for Request("state") and if there is a value load the propper items in combo2.

well if you want to change comboboxes items without having to postback , your gonna have to change them with javascript.

if you really do not want to rely on javascript , then you can manage your postbacks with querystring, Session variables , or even cookies but that would be overkill, Session would be fine.

Lets say Combobox1 is States and combo box 2 is Towns or whatever.
When user changes the selectedIndex of combo1 , save the new selectedIndex in a Session variable Session("state") , then on your page load check if postback is true and if it is, check if you have a value for Session("state"), if you do, load the proper items in combo2

alternatively with querystring simply redirect to the same page with "state=UserSelection" at the end of the link ("mypage.aspx?state=something") , and in your page load check for Request("state") and if there is a value load the propper items in combo2.

hi Phillipe,

Thanks for your post. I managed to solve my issue. I used if (Page.IsPostBack == true) and this sorted out the whole issue and now my form behaves exactly the way I require it to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.