views:

33

answers:

3

For a <select> control, we can use the onchange attribute to run some javascript when the option value changes. Intellisense would lead me to believe that the asp:ListBox control does not hold this attribute (as you'll get underlining in visual studio telling you that this is invalid). However, this works.

<asp:ListBox  ID="roleList"  OnChange="someJavascriptCall()" runat="server" Visible="true" Rows="3">

Try typing that code into visual studio, and you'll have your OnChange attribute calling you out. Why is this? Are there any side effects to using this attribute?

A: 

That is the common syntax for declaratively assigning serverside event listeners, so it could be very confusing to read your code, if nothing else.

David Hedlund
+1  A: 

It's not a valid attribute for the asp:Listbox control but it is a valid one for the html select control. Intellisense is just warning you about the former.

Tom
+1  A: 

OnChange isn't part of the ListBox class so the ide shows it as invalid. However when it gets rendered in to html it passes along those non class member attributes in to the html. Same thing could be said for embedding styles using style="color:red;" or something like that.

gjutras