views:

830

answers:

3

When I try to write code like the following source code, Visual Studio doesn't show any Intellisense for current context. Moreover, it tells me that another "<% %>" brackets is incorrect.

<div>
    <input type="checkbox" title="<%= LogOnView.RememberMe_ToolTip %>" />
</div>

How to solve this problem by patch or VSPackage(if you have some source code for modify existing Intellisense, I will add your source code to my VS Package)?

PS. I'm using Visual Studio 2008 SP1 with .NET 3.5 SP1

A: 

I think it needs a hint to process that in ASP.NET.

Try using

<div runat="server">
    <input type="checkbox" title="<%= LogOnView.RememberMe_ToolTip  %>" runat="server"/>
</div>

Alternatively, you can do it in .NET with (might need a <%@Register%> at the top though):

<asp:Panel runat="server">
   <asp:CheckBox runat="server" ToolTip="<%= LogOnView.RememberMe_ToolTip %>"/>
</asp:Panel>
Dominic Zukiewicz
This is just plain wrong. Neither of these suggestions will even execute the code block because you can't use `<%= %>` inside server tags, only in literal text. This will just end up with `"<%= LogOnView.RememberMe_ToolTip %>"` as your tool-tip.
McKAMEY
By the way, the easiest way to solve this question is writing all tag in Asp.net Server Control and setting all property in code-behind. But it isn't Asp.net MVC coding style.
Soul_Master
+3  A: 

This is just a shortcoming in the Visual Studio HTML designer component. If you pull the code block outside of the attribute it works great, once you put <%= %> in the attribute it no longer gives you proper IntelliSense in that block. I've even had this within a style="<%= %>" attribute go totally haywire and won't even get the syntax color correct (tries to parse it as CSS).

My theory is that the parser is in the context of that tag and attribute so it is trying to interpret what you are doing as values of that attribute. For instance, when you type the open quote of the type=" it knows to show you a list of common values for that tag. If you try to invoke IntelliSense in the middle of type="<%= %>", it will show you that same list of values which is not what you would expect in this code block context.

I experience this same exact issue when using the Visual Studio syntax coloring for editing JBST client-side templates. The markup is identical but the syntax coloring freaks out every so often.

I'm betting that there isn't a fix for it as it is pretty core to the designer. Best bet is to wait for a future release. I haven't tried this in Visual Studio 2010 to see if they've fixed it.

McKAMEY
For you answer, I want to know only 1 question. Is it possible to fix this problem by modifying intellisense in Visual Studio HTML designer with Visual Studio Integration Package. It’s very important for coding with Asp.net MVC. Thanks.
Soul_Master
Unfortunately I don't believe so. When Microsoft updated Intellisense to better work with certain JavaScript libraries (e.g. jQuery) they released it as a VS Hotfix which patched VS itself. I don't believe the current version of Visual Studio is pluggable enough to override Intellisense behavior, but from what I understand this may be a reality in a future release.
McKAMEY
A: 

I just installed Visual Studio 2010 Beta 1 and it doesn't work in this version either. I really hope they fix this before the final release.

Jordan