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

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

1 Answer 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bryan
Top achievements
Rank 1
Bryan asked on 10 Nov 2015, 09:14 PM

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.

1 Answer, 1 is accepted

Sort by
0
Bryan
Top achievements
Rank 1
answered on 10 Nov 2015, 10:43 PM

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... 

Tags
General Discussions
Asked by
Bryan
Top achievements
Rank 1
Answers by
Bryan
Top achievements
Rank 1
Share this question
or