Setting text and value via Javascript

4 posts, 0 answers
  1. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 20 Nov 2012 Link to this post


    On webpage load, I populate a RadComboBox with text and keys. I have a default value I assign then on server-side too.

    If they click a button to clear the form, I blank out all controls, but populate defaults. I need to do it client-side, and I'm having trouble with RadComboBox. I thought I'd populate a hidden field with the RadComboBox's default text on server-side during the load, then assign that value client-side when needed. I've tried both set_text (and set_value with the hidden field holding the default value instead) but when it evaluates later, it appears either the text is right but the value isn't, or vice versa.

    Do I have to track in 2 hidden fields (both  default text and default value) and assign both client-side? That seems goofy, but if so, in what order should it be done? Or can I do this without tracking both the text and value default?

    Example javascript code would be very welcome, assuming the hidden fields are populated... unless I should do it a completely different way.

  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 20 Nov 2012 Link to this post

    Hello Jeremy,

    If you're changing anything on the RadComboBox from the client-side you need to call the trackChanges and commitChanges methods, in order for the state of the RadComboBox to persist on the server-side.

    You code should look like this:

    Javascript:
    var combo = $find("<%=RadComboBox1.ClientID%>");
     
    combo.trackChanges();
    combo.set_value("Test");
    combo.commitChanges();

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 26 Nov 2012 Link to this post


    This javascript changes the value of the combobox, but the text value displayed does NOT change. I need both to change, or the display conflicts with the actual value.
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 29 Nov 2012 Link to this post

    Hi Jeremy,

    I can suggest you to store both the text and the value of the default item in the HiddenField. You could use a comma as separator and split them in client-side, in order to access the text and the value. I have prepared a sample project for you demonstrate you the suggested approach. Please find the sample attached.

    Regards,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top