webservice & selectedValue

8 posts, 0 answers
  1. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 10 Apr 2008 Link to this post

    I am trying to use the WebService to populate my drop down.

    Now, when I show the dropdown first time I need to show a selected item. What is the recommended way of doing that? because setting selectedValue does not have any effect because there is not data bound to it from server side!!

    Thanks,
    Piyush
  2. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 10 Apr 2008 Link to this post

    One way I did it was setting the Text property while loading the page.

    The other problem I am facing now is:
    - I set the SelectedValue from the code behind
    - I used keyboard to delete the content of combo box to indicate that no value is selected
    - I postback - the post back event remembers the original Selected Value and on the server side I don't know if the value is unselected! My AllowCustomText is set to False.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 11 Apr 2008 Link to this post

    Hello Piyush,

    You could hook on the OnClientItemsRequested event that is fired right after the items have been populated. There, you can find the needed item and select it using the client-side object model of the combobox:

    function OnClientItemsRequested(sender, args)
    {
         var combo = sender;
         var neededItem = combo.findItemByText("text");
         neededItem.select();
    }

    Hope this helps.

    Sincerely yours,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 11 Apr 2008 Link to this post


    The OnClientItemRequesting will get called when I click on the combo box or type something in. So, this wouldn't work.

    I have to display the form with selected value. Currently I am setting Text property from the code behind.

    -Piyush
  6. Alan Johns
    Alan Johns avatar
    1 posts
    Member since:
    Oct 2012

    Posted 15 Apr 2008 Link to this post

    What is the best practice here?

    When you populate a form from a database and show the user the values in the load-on-deman dropdowns, where do you store the value from the database? I can show the Text in the combobox to the user, that's no problem. I was using the .value property with the older radControls to store this, but it's been removed from the Prometheus version.

    It's possible the user will not touch the combobox and the OnClientItemsRequested event will never get fired. In this case, where's the value of this combobox supposed to come from when the user submits the data back to the server? It won't be in selectedvalue...

    Thanks,

    -Alan
  7. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 16 Apr 2008 Link to this post

    Hi there,

    Piyush, I meant the OnClientItemsRequested event, not the OnClientItemsRequesting. The OnClientItemsRequested event is fired when the items have been completely loaded.


    Alan , the SelectedValue property of the combobox Prometheus should now return the selected value even in a callback mode. Did you mean that the SelectedValue property is empty at the server side?

    Regards,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 16 Apr 2008 Link to this post

    Nick,

    When a page is rendered, if the user has not clicked on the drop down, will OnClientItemRequested() get called?

    One may have 1000 items in database. And web-service would return only (for better performance) 10 or 20 as per what user types in. Now, how following would work if web-service won't even return that item?

    var neededItem = combo.findItemByText("text");

    Another - the selected value is actually on the server side. So, we would have to put it into some other control to make it available on the client side and then use above method.

    Also, it needs to be selected only when the page renders first time and not after user selects some other item from the drop down. So, we would have to check using javascript whether this is first time or whether user has selected some different value already.

    Don't you think this would be too much? I like to set the initial selected value and text property from code behind when page renders. Hopefully it should be the right practice according to telerik.

    -Piyush
  9. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 17 Apr 2008 Link to this post

    Hello Piyush,

    You will not be able to select any item if no items have been previously added to the combobox. You can, however, set some text to the input field when the page is first rendered. For example, you can use the pageLoad event and set some default text to the input part of the combobox, like:

    <script>
       function pageLoad()
       {
            var comboBox = $find("<%=RadComboBox1.ClientID"%>);
            comboBox.set_text("text");
       }

    </script>

    Additionally, you can set the default text only if the items have not been loaded yet:

    if(comboBox.get_items().get_count()==0)
    {
       comboBox.set_text("text");
    }

    I hope that this is acceptable for you.

    Kind regards,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017