Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Visual Studio Intellisense automatically insert runat="server"?

For any of the common "asp:__________" controls (asp:gridview, asp:repeater, etc) I always add runat="server". Is there any good reason that Intellisense shouldn't insert this automatically?

like image 441
Larsenal Avatar asked Jul 14 '09 23:07

Larsenal


2 Answers

What if you really wanted to output something like <asp:xyz>? For example, if you wanted to generate an XML document with namespaces, you might want to use that template without any runat="server", like:

<root xmlns="..." xmlns:asp="...">
   <asp:GridView>
       <name><%= Request["name"] %></name>
   </asp:GridView>
</root>

While I agree this might not be the common case, it's at least a good reason to require runat="server" in the first place rather than just assuming it. However, it's not always very clear where you want to specify it and where you don't want. Note that there are HtmlControls too. Moreover, you can define your own prefixes too. That said, I personally think VS IntelliSense system is designed not to interfere with normal typing. That is, it never works like "I think you need it most of the time. In the 1% of cases you didn't, manually remove it."

like image 126
mmx Avatar answered Oct 15 '22 06:10

mmx


You could always use something like this add-in, which inserts the runat="server" attribute for you (source code available).

Edit: the add-in has gone from it's original home, but got ported to VS2010 and now lives at http://www.rowlandoconnor.com/2010/04/16/aspx-edit-add-in-for-visual-studio-2010/

like image 20
stuartd Avatar answered Oct 15 '22 05:10

stuartd