Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Intellisense vs. Client-Side Attributes

Tags:

I am just getting into more client-side stuff in ASP.NET using Javascript, and there's something that's bothering me that hopefully somebody can explain. Why is it that intellisense doesn't show the all of the attributes/properties of a .NET control? For example, a ListItem in a RadioButtonListControl:

<asp:ListItem Value="1" Text="Yes" onclick="alert('TEST1');" />
<asp:ListItem Value="0" Text="No" onclick="alert('TEST2');" />

Intellisense doesn't show the onclick property (or is it called attribute?) of the ListItem, but it sure works. Why doesn't it show? Or am I relying on Intellisense too much? :-) Or should I be declaring this stuff in code-behind?

like image 261
Mike Cole Avatar asked Apr 25 '09 16:04

Mike Cole


2 Answers

The issue is that intellisense for Web server controls does not display client side events and only lists events that are raised on the server. If you were to use an HTML server control for the same purpose you would see the (client-side JS) events in Intellisense.

Another issue to consider is that the onclick event isn't supported for option elements (atleast not in IE, though Firefox supports it fine). You should instead handle the onchange client side event. An example :

<select id="htmlserverselect" runat="server" onchange="alert(this.value);">
  <option value="1">Yes</option>
  <option value="2">No</option>
</select>
like image 96
Cerebrus Avatar answered Oct 12 '22 08:10

Cerebrus


It depends a lot of times on the control you are working with and the attribute. I know that ASP button controls will show the onclick and the onclientclick attributes in intellisense. It may be that ASP.NET doesn't fully support the onClick attribute for the listitem (as opposed to say the selectedindexchanged attribute on the listbox/dropdownlist/etc controls)

like image 22
TheTXI Avatar answered Oct 12 '22 09:10

TheTXI