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

How can I change a hidden form field on postback?

13 Answers 114 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
CynthiaD
Top achievements
Rank 1
CynthiaD asked on 26 Aug 2008, 12:14 AM
OK, I am used to the "classic" RadComboBox, the one where you had a RadCallback control where you could set the "ControlsToUpdate" property to tell it which controls were going to be visible on callback. In that way, I could set the value of other controls on the page.

Now, with the ASP.NET AJAX combo box, I do not know how to do that.

When I try to set the value of a hidden form field (type HiddenField) in the ItemsRequested event handler, it does not work.  On the next callback, the value has not been changed.

Exactly how can I change the value of another control on the page?

13 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 26 Aug 2008, 10:27 AM
Hi ,

I suggest you check our help article - Controls are not updated during the ItemsRequested event.


Kind regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CynthiaD
Top achievements
Rank 1
answered on 26 Aug 2008, 06:08 PM
Thanks.  That article suggests using a RadAjaxPanel with the ComboBox to do a normal callback that will give access to other server controls.

But will the "load on demand" features still work if I do that? Can I still use the ItemsRequested event handler?
0
CynthiaD
Top achievements
Rank 1
answered on 26 Aug 2008, 06:13 PM
Also -- I just tried setting the SelectedIndexChanged event handler for the combo box with EnableLoadOnDemand set to true and ShowMoreResultsBox set to true.

After I click the ShowMoreResultsBox to append another set of data, and then I select an item, the SelectedIndex is -1 in the event handler.

Selecting an item does not seem to work after you have clicked the ShowMoreResultsBox.

Could you explain why please?
0
Rosi
Telerik team
answered on 29 Aug 2008, 02:12 PM
Hello ,

There is no way to update the hidden field in ItemsRequested event handler. The article suggests using the RadAjaxPanel instead of using LoadOnDemand feature. Using LoadOnDemand feature and Ajax update is not recommended.

Also when your items are loaded on demand they are not persisted on the server after postback. That is the reason why the SelectedIndex returns -1. You can access the Text and Value properties of the RadComboBox only.


Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CynthiaD
Top achievements
Rank 1
answered on 29 Aug 2008, 05:02 PM
So how are you supposed to retrieve the item the user selected in the combo box after the user has clicked the ShowMoreResultsBox?

Since the SelectedIndex does not change, the SelectedIndexChanged event does not fire.  How are you supposed to know when the user selected a different item?
0
Yana
Telerik team
answered on 01 Sep 2008, 01:32 PM
Hello,

When the user clicks ShowMoreResultsBox, new items are appended to RadComboBox but the selected item doesn't change. If he then selects a different item, then SelectedIndexChanged is fired.

Regards,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CynthiaD
Top achievements
Rank 1
answered on 02 Sep 2008, 05:05 PM
OK, you are right that selecting an item after clicking ShowMoreResultsBox causes the SelectedIndexChanged to fire, and it does return the correct SelectedIndex.  It does work. I was wrong; don't know why I thought that.

However, in addition to ShowMoreResultsBox=True, I also have MarkFirstMatch=True, and I have it set up so that if the user types in one or more letters, it shows all the items that start with those letters in the ComboBox.  I do this in the ItemsRequested event handler.  I check to see if the user clicked the ShowMoreResultsBox; if not, I know that they are using the MarkFirstMatch feature.  In that case, I execute a Sql statement with a LIKE command that only returns items that start with the characters that were typed in.

After doing that, if the user selects an item from the list, at that point, the SelectedIndex is -1 no matter what is selected.

Also, at that point, the list returns to its original state: showing the first 10 items. The list of items that begin with the characters the user typed in is completely lost.  The text box still shows the item they selected, but the list itself does not contain that value.

How am I supposed to find the item the user selected so I can do something with it?
0
Yana
Telerik team
answered on 05 Sep 2008, 09:18 AM
Hello Cynthia,

Please check our online example which demonstrates how to use Load On Demand feature of RadComboBox with ShowMoreResultsBox and MarkFirstMatch properties set to true.

Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CynthiaD
Top achievements
Rank 1
answered on 05 Sep 2008, 04:05 PM
So you have to have a SELECT button to officially select the item you have chosen from the combo box list?  That's the only way?
0
Yana
Telerik team
answered on 08 Sep 2008, 01:15 PM
Hello Cynthia,

The SELECT button is only for the example, you don't need to have a button to officially select an item.

Greetings,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CynthiaD
Top achievements
Rank 1
answered on 08 Sep 2008, 04:31 PM
OK, well then I have to go back to my previous question:  how do I get ahold of the selected item, because the SelectedIndex is -1 when I select an item after typing in some text and getting a match. (NOT in a normal combo box that has MarkFirstMatch=true, but only when I am using the LoadOnDemand feature, such that there is a ShowMoreResultsBox.)

To repeat:

I have it set up so that if the user types in one or more letters, it shows all the items that start with those letters in the ComboBox.  I do this in the ItemsRequested event handler.  I check to see if the user clicked the ShowMoreResultsBox; if not, I know that they are using the MarkFirstMatch feature.  In that case, I execute a Sql statement with a LIKE command that only returns items that start with the characters that were typed in.

After doing that, if the user selects an item from the list, at that point, the SelectedIndex is -1 no matter what is selected.

Also, at that point, the list returns to its original state: showing the first 10 items. The list of items that begin with the characters the user typed in is completely lost.  The text box still shows the item they selected, but the list itself does not contain that value.
0
Yana
Telerik team
answered on 09 Sep 2008, 02:37 PM
Hello Cynthia,

Could you please send us a working example which demonstrates the described issue, so we can test it locally? You should open a support ticket to be able to attach files. Thanks

Best wishes,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CynthiaD
Top achievements
Rank 1
answered on 09 Sep 2008, 07:52 PM
Thank you -- I have submitted a support ticket with a test project to illustrate the problem.
Tags
ComboBox
Asked by
CynthiaD
Top achievements
Rank 1
Answers by
Rosi
Telerik team
CynthiaD
Top achievements
Rank 1
Yana
Telerik team
Share this question
or