Gotcha: Lost HTML Intellisense within ASP.NET AJAX Controls

Symptom:

You are using ASP.NET AJAX Beta1 or Beta2, and create a .aspx page that is based on a .master file.  You add the <asp:scriptmanger>, <asp:updatepanel>, <asp:updateprogress> or <asp:timer> control into the content page, and find that markup intellisense no longer works for these controls, or for any controls nested within them:

In the screen-shot above notice how the ScriptManager, UpdatePanel and ContentTemplate tags have the little red-squiggly lines underneath them.  You also won't get tag completion when you type these elements in the document.  You can still compile and run just fine, and the WYSIWYG designer works just fine.  But you do lose source editor intellisense.

Some Background on the Issue:

ASP.NET 2.0 added support for registering controls (both compiled and .ascx user controls) within your web.config file - removing the need to always add <%@ Register %> directives at the top of your page.  For more details on this and to see a sample in action, please check out my Tips and Tricks talk from the recent ASP.NET Connections conference.

One of the cool aspects of this feature is that it also now allows you to map the same tag prefix against multiple assemblies.  We use this with ASP.NET AJAX to have these controls use the <asp:> tag prefix, even though they live in a separate assembly from the system.web.dll file that contains the rest of ASP.NET.

Unfortunately we discovered a bug with the VS markup intellisense engine when doing the ASP.NET AJAX Beta1 release - which is that you lose intellisense when you map multiple assemblies against the <asp:> tag prefix and use the controls within a <asp:content> control in a .aspx page based on a master page. 

How to Fix This

The fix for the intellisense issue will be in VS 2005 SP1.

In the meantime there are two workarounds that you can use to fix it immediately:

1) Keep the .master file open within the Visual Studio IDE when working on the .aspx content page.  It turns out the intellisense engine only runs into issues if the .master file is closed.  As long as it is open within the same IDE, it resolves the assemblies just fine and will give you full intellisense:

The screen-shot above is with the exact same sample as the previous screen-shot.  The only difference is that I also have the Site.Master file open in the editor in the background.  When that file is open, I get full intellisense for the ASP.NET AJAX control elements and no intellisense errors.

Alternatively you could instead use the below technique if you don't want to keep the .master file open:

2) Go into your web.config file and change the tag-prefix naming for the ASP.NET AJAX controls to something other than <asp:>.  For example, instead of:

      <controls>
        
<add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
        <
add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
      </
controls>

 

change them to something like this:

 

      <controls>
        
<add tagPrefix="ajax" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
        <
add tagPrefix="ajax" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
      </
controls>

You'd then want to update your tag prefixes in your .aspx page to use this new tag prefix.

Either of these approaches will solve the problem and deliver full intellisense.  The issue should then be resolved completely with VS 2005 SP1.

Hope this helps (and sorry for the inconvenience),

Scott

40 Comments

  • Thanks Scott,
    I'm, recently building Ajax enable apps, I realised the problem that you stated above, but I wanted to ask you on how mark around it, but when I created single page that did not inherit from master page I was able to have full intellisense capability, then I decided to use simple page to gain my full intellisense capability then copy the codes to in-herited aspx pages where I need full ajax capability.Now with your tips, I think I don't have to use copy and paste method from non-inherited page. Thanks a lot scott. Reading your blog is a must for any asp.net developer

  • Awesome tip Scott. Thanks for sharing.

  • Hi Mohammed,

    Yep -- the lost intellisense issue actually only happens when you have a page based on the master-page. It doesn't happen with a standalone page. I think it has to-do with how we handle controls - which are somewhat special in the VS parser.

    Thankfully you can use the tip above to fix it. :-)

    Hope this helps,

    Scott

  • Scott

    You mentioned the VS 2005 SP1. Any hints at a release date for that? (or did i miss it somewhere)

  • Hi Matt,

    VS 2005 SP1 is getting really close. They are just taking in a few last additional fixes now. You can download VS 2005 SP1 Beta today - which has more than 1200 fixes already in it (and which people have been giving great feedback on). We are hoping to have the final release out soon.

    Thanks,

    Scott

  • Yep, I encountered this problem a few weeks ago. I fixed it by modifying the tag prefix naming in the web.config (#2 from above) - it's been smooth sailing ever since.

    Oh, and BTW thanks for coming to Dallas it was great meeting you and seeing your presentation at the NDDNUG!

    -Shane

  • I've noticed this error, when using nested master pages and without AJAX. The solution is to open both mater pages.

    Cheers

    -Kenneth

  • Hey Scott,

    Thanks for the post. We are also noticing a similar problem when using nested master pages. Is this related to this as well?

    Thanks

  • Hi Doug,

    Yep - I believe this is the same issue. Keeping the root master file open should fix it for you.

    Thanks,

    Scott

  • Great tip scott. This blog entry is going in my weekly update to my team. Clears up this rather confusing behaviour in an otherwise stellar product. :)

  • Hi Scrott,

    Your workarounds works for webcontrols but I can't get intellisense within usercontrols
    like when adding them to web.config? We use nested master pages.

    - Kristoffer

  • What about when you don't reference the master page explicitly, but instead just use web.config? I have red squigglies everywhere because of that currently.

  • Hi Kristoffer,

    Can you clarrify what intellisense issue you are having with user controls? User controls typically don't/can't have inner contents.

    Thanks,

    Scott

  • Thanks Scott. I thought our dev team had a problem that no one else had. Now I know we're not all nuts! (That's one less reason we're nuts, in any case.)

  • Thanks, Scott! I just ran into this this week as well and was scratching my head wondering what I'd done wrong. Sounds like the same kind of fix as the "intellisense doesn't work with nested master pages unless the master page is open" bug -- do you know if that one is also fixed in VS 2005 SP1?

  • wow, good trick, But you have left we wondering what are you people doing with the studio that it works fine when the master page is open in the studio. If you can provide some insight on what is it that removes the problem when the master page open.

    Just wondering about it

  • I don't know if this is related but since installing beta 2 VS now intermittently really screws up my html code when switching between design and code view.

    It not only removes all the formatting but changes the tags to include capitals e.g becomes , becomes etc.

    Has anyone else seen this?

  • Hi William,

    Can you send me an email with more details about the error you are seeing? I haven't heard/seen anyone else report this and would like to have someone on my team investigate.

    Thanks,

    Scott

  • Hi Scott,
    I encountered an odd bug of asp.net ajax both on beta and beta2. The UpdatePanel works fine in a page which has a MasterPage or has a ReportViewer. But when I put UpdatePanel, MasterPage and ReportViewer all together, an interesting bug occurs:@ -- The UpdatePanel works just fine on the first async-postback, but on the second time it fail! I get a error messagebox in IE, the errmsg is: "Specified argument was out of the range of vaild values."
    I traced into the error and I found the error was thrown by ReportViewer on the serverside.
    I need MasterPage, ReportViewer and asp.net ajax all together and my project is too pressing to let me fix this bug myself. Can u guys fix it ASAP?
    --- Yours: feng

  • tnks for the tip, VStudio is nothing without intellisence

  • why my reply did not appear in the reply list?

  • I can confirm the HTML error that William reported above. In a page based on a master page, everything within the ContentTemplate gets all line breaks stripped out when switching between design and code views, and all of the html tags switch to all caps.

    Also, I can't get the Beta2 intellisense workaround to work. I have all of my master pages open, even the ones not related to the page I'm working on, have restarted the IDE, have switched to debug mode then back, and the Update Panels are still not recognized. I thought my HTML bug was related to this, but I guess not. Do I have to open pages in a specified order?

  • Hi Adam,

    Can you send me email with more details about the html capitalization issue you are seeing? I'd really like to understand it better.

    On the intellisense issue, have you tried doing the second approach I suggested above - which is to change the tagprefix name?

    Thanks,

    Scott

  • Hi Feng,

    I'm not sure whether the ReportViewer control works with UpdatePanel yet (note: this is a control that isn't shipped by ASP.NET).

    If you want to send me email, I'd be happy to connect you with the SQL Reporting Services team to see if they have some suggestions on how to make it work or when it will be enabled.

    Thanks,

    Scott

  • Hi Scott,

    Thanks for this very helpful post. Now I'm noticing that I'm getting blue squigglies in my code behind page when I try to reference a control that is within my update panel. It works fine in a regular page, but not one based on a Master. Have you seen this as well?

    Thanks,
    Chris

  • Hi Chris,

    I haven't heard of an issue like that before. Are you keeping the master page open?

    Thanks,

    Scott

  • Hello Scott,

    Thanks for this useful tip which works with Visual Web Developper 2005 Express too. Now i'm no longer having trouble using ajax and masterpages.

    Thanks again,
    Kevin

  • ACTUALLY... follow-up question or maybe solution (3).

    I had a sub-folder of my root directory with a different master page for the content pages in that directory. Those seemed fine with intellisense.

    I changed my root folder page to use the subfolder master page. It suddenly seemed fine (except that's not the right page).

    I drop my root folder master page into the sub-folder and re-assign the master page - everything is fine.

    SO I just created a MasterPages folder off my root, put my master pages in there, and my intellisense is working again - for now...

  • I'm having the same problem as a couple other people above. First, I get red sqigglies for my user controls added via the web.config. And I also get blue squigglies in my code-behind files for any controls on the page (any they don't show up under the Class and Method drop downs to easily add event handlers). I get normal intellisense for those same controls in the .aspx files, however. Happens on every page, even ones not using Master Pages. I've nailed down the problem to having any tagMappings in the web.config that map to the AJAX Futures CTP. If I comment out those tagMappings, then intellisense catches both my web.config controls and my normal controls in the code-behind (all squigglies go away). tagMappings that map to the AJAX RC (System.Web.Extensions) do not cause this problem. Even if I map a tag to a type that inherits a Microsoft.Web.Preview type, the intellisense errors above occur. If I remove the inheritance, intellisense resumes working. Any ideas? Thanks.

  • None of these approaches work with AJAX extensions release candidate and VS 2005 SP1. I am still seeing red underlining and Intellisense doesn't work, no matter what I do.

  • Actually, I am wrong. If I create a new, AJAX enabled website and using the tag renaming approach ("ajax"), it works fine with AJAX RC and VS 2005 SP1. But the bug still exists.

  • Hi Jon,

    To fix the ASP.NET AJAX Intellisense issue, you need to do the following step with VS 2005 SP1:

    Delete the cached schema files for control markup Intellisense that VS maintains. This will ensure that your HTML source editor Intellisense for the ASP.NET AJAX controls is correct and doesn't get lost (otherwise it might incorrectly use the old values from the Beta2 release).

    - With Windows XP you do this by deleting all files in this directory: c:\Document and Settings\[YourUserName]\Application Data\Microsoft\VisualStudio\8.0\ReflectedSchemas

    - With Windows Vista you do this by deleting all files in this directory: c:\Users\[YourUserName]\AppData\Roaming\Microsoft\VisualStudio\8.0\ReflectedSchemas

    Once you delete these schema files and restart VS, it will re-calculate the HTML markup Intellisense for all controls the first time you switch into design view, and pick up the changes from the assembly name change.

    Hope this helps,

    Scott

  • These approaches did not solve the nested master page problem, either. Intellisense does not appear to work inside any declarative code. (My DetailsView and SqlDataSource were both filled with red squigglies and did not have Intellisense.)

    I tried keeping the master pages open in the IDE, loading SP1, and clearing the files from the ReflectedSchemas folder.

  • Hi Dan,

    Can you send me an email with details on this? I'll then loop in some folks from my team to help investigate.

    Thanks,

    Scott

  • I just sent the requested email.

    Thanks,

    Dan

  • I have found ur page after a month of tearing out my hair. Thanks a lot scott for the update.

  • Thanks! This helps a ton. I thought I was going crazy because for the life of me I couldn't get it to work correctly.

  • You may also want to mention that if you have the master page open already, you may have to close and re-open it. This is especially if you're working with Visual Sourcesafe.

    I often have to close down and open up the master page to regain the intellisense.

  • Thanks, this helped out perfectly.

  • Thanks Scott. You've been a big help. Your work is much appreciated.

Comments have been disabled for this content.