This is a migrated thread and some comments may be shown as answers.

SelectedValue does not change after postback

6 Answers 285 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 2
Martin asked on 23 Jan 2008, 03:33 PM
Hi,

I am using the Prometheus RadComboBox in a custom web control, to display and select place names (with a corresponding place id). In once instance I am using the control on a user profile page to show the user's hometown.

On the custom control I have a public attribute of 'SelectedId' which I use to populate the RadComboBox when the page loads - the id and place name of the user's hometown are turned into a RadComboBoxItemData and is added to the control. This works fine.
public string SelectedId 
        { 
            get 
            { 
                int result; 
                if( !int.TryParse(_RadGroupBox.SelectedValue, out result)) 
                { 
                    result = 0; 
                } 
                return result.ToString(); 
            } 
            set 
            { 
 
                // Place is just a custom object with a name and id.   
                Place place = new Place(Convert.ToInt32(value)); 
                place.PlaceId = Convert.ToInt32(value); 
 
                RadComboBoxItemData itemData = new RadComboBoxItemData(); 
                itemData.Value = value; 
                itemData.Text = GroupFormatter.GetLongDisplayName(place); 
                RadComboBoxItem item = new RadComboBoxItem(itemData.Text, itemData.Value); 
                item.Selected = true
                 
                _RadGroupBox.Items.Add(item); 
                _RadGroupBox.SelectedIndex = 0; 
            } 
        } 

My problem when you try use the combobox on the page to change the user's hometown. Using LoadOnDemand, the combox successfully lets you select another place. Debugging client side before posting back the update to the profile, I can confirm that the selected value of the combox is the id of the new place selected.

However, when I postback to the server to try and save the changes, the SelectedId of my custom control always returns the original value, instead of the newly selected value.

In the get section
get 
            { 
                int result; 
                if( !int.TryParse(_RadGroupBox.SelectedValue, out result)) 
                { 
                    result = 0; 
                } 
                return result.ToString(); 
            } 

My _RadGroupBox.SelectedValue always holds onto the original value. The setter is not being hit, so I know that the control is not being repopulated from the database. At the same time, the _RadGroupBox.Text correctly contains the new selected place name. It is just the SelectedValue that is not being passed in.

Hopefully this makes some sense to you. I understand its hard to follow unless you can see the whole project, but hopefully you might be able to offer some advice.

Thanks,
Martin


6 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 25 Jan 2008, 03:57 PM
Hi Martin,

I am afraid there is nothing much we can do without testing your project locally .

SelectedValue returns the correct value on our side - see our online example for a reference.

The only thing I can suggest you not to set _RadGroupBox.SelectedIndex = 0 every item when you add new item.

Try this and let us known how this goes.

Hope this helps.

Greetings,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Martin
Top achievements
Rank 2
answered on 25 Jan 2008, 04:12 PM
The _RadGroupBox.SelectedIndex = 0 isn't the problem. That was a line I added in to try and fix the problem, but it made no difference.

We think its someting to do with the fact that we are using a web service for the LoadOnDemand, but dynamically adding an item to the control when the page loads to display the value stored in the database. It appears that this value is getting stored in the ViewState and is not overridden by the new value selected on the LoadOnDemand when you postback.

I appreciate that
theres is nothing much you can do without testing our project locally. I assumed that might be the case.
0
Rosi
Telerik team
answered on 28 Jan 2008, 03:55 PM
Hi Martin,

Please find attached simple project based on your approach. It works as expected on our side. Could you modify it so the problem to be isolated? This will really help us to understand the problem better and find a solution.

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Martin
Top achievements
Rank 2
answered on 28 Jan 2008, 04:00 PM
Thanks for doing this, but we have already created a sample project and uploaded it with a support ticket. #118790
0
Accepted
Rosi
Telerik team
answered on 29 Jan 2008, 01:39 PM
Hello Martin,

Please, find attached latest build of Telerik.Web.UI. Download it and test it.

This should helps.

All the best,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Martin
Top achievements
Rank 2
answered on 30 Jan 2008, 04:18 PM
Hi we have included these new ddls in our project, and it seems to have fixed the problem. Sorry for the delay responding. We are having problems testing due to other unrelated problems with the build.

Looking good so far though. Thanks very much for your help.
Tags
ComboBox
Asked by
Martin
Top achievements
Rank 2
Answers by
Rosi
Telerik team
Martin
Top achievements
Rank 2
Share this question
or