Fire OnClientItemSelected event using JavaScript (or just get the selected value)

2 posts, 0 answers
  1. Bryan
    Bryan avatar
    2 posts
    Member since:
    Nov 2015

    Posted 10 Nov 2015 Link to this post

    Okay, so I have a setup where by selecting a raddropdown, JavaScript looks at the selected item's value to get an index to show one of three types of input boxes (text, number, and date; each start as displayed and then hides two of them).

    While I can make that happen easily enough when the dropdown is selected, if I do any kind of a postback on the page (such as selecting to go to the next page of a radgrid), the function never runs again and then all three types of boxes display. I have tried to get the ID of the raddropdown, and then use that to fire off the event but that does not work as $find gets me nothing and $get gets an object that is neither the sender nor the eventArgs parameters for the event.

    So, i either need to know how by using $get to get the selected value of the dropdown or make JavaScript fire the "OnClientItemSelected" event so then my code will fire off and hide the appropriate text boxes. And unless I am missing the obvious, the 'normal' JavaScript function I have used in the past (ddl.options[ddl.selectedIndex].value) will not work as the object isn't actually a dropdown as JS seems to see it...

     Any help on this is much appreciated.

  2. Bryan
    Bryan avatar
    2 posts
    Member since:
    Nov 2015

    Posted 10 Nov 2015 Link to this post

    Okay, i found the crux of my issue - whenever a postback occurs from something other than the dropdown list, the "selected index" of the dropdown is reset to -1 (basically "not selected"). However, the visual aspect of it still shows the item I selected... which makes no sense if the index is set back to -1... which then also makes it impossible to "reset" it via javascript, as nothing is actually selected... 

     

    So, unless someone says otherwise, it looks like I have to store the selected value in a hidden text box somewhere and then reference that in my code-behind in postback, then reset the value from there, as that works just fine... 

Back to Top