Obtain value of combobox in script

7 posts, 1 answers
  1. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 07 May 2010 Link to this post

    Very simple scenario here,

    Got 2 Combobox's when either of them change value, i want a label to display the value.

    Without a postback, so js / ajax


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 May 2010 Link to this post

    Hello,

    You can attach the 'OnClientSelectedIndexChanged' event to RadComboBox and get the selecteditem text in the client event handler using  "eventArgs.get_item().get_text()" method, then show the value in label text.

    You can find out more client side methods of RadComboBox object here:

    Client-Side Basics

    RadComboBox object

    -Shinu.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 07 May 2010 Link to this post

    Hi Shinu,

    I can get the value ok, but am struggling to set a label's value to it.

                     var county = document.getElementById("<%= lbl_countrydisplay.ClientID %>");
                     country.set_text = text


    Tried something like that, also tried your standard JS funcitons like .value
  5. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 07 May 2010 Link to this post

    If you want to the set the value in the label it would go like this:

    country.innerHTML = value;
  6. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 08 May 2010 Link to this post

    yeah tried that, that changes on the screen, but if i try access it server side it still has the old value. Ie, i need to do something with the value of the label server side and doing label.text isn't returning the updated value.
  7. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 09 May 2010 Link to this post

    Does this do anything?
  8. Answer
    Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 11 May 2010 Link to this post

    Alan,

    This is more of a general ASP.NET Ajax issue, but basically what you are setting as the label's text via javascript is not being persisted to the code-behind. One way to address this would be to take use of hidden fields and set their value equal to what you just set the label's innerHTML equal to. An example of this can be found in this ASP.NET forum thread.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017