Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

ASP.NET Designer Control Problem in VS 2008 SP1


:P
On this page:

I’m having a pretty nasty problem with the VS 2008 Designer in SP1. Apparently from time to time the Web designer decides it doesn’t like to assign simple property values for controls anymore and starts displaying errors for individual controls on the form.

Here’s what this looks like in the designer:

DesignerBug

Designer errors can happen for lots of reasons, but since I installed SP1 I’ve been seeing the above quite frequently with my own custom controls as well with several third party controls.

What’s odd about the error above is that the control works at first. Stays on the page everything is editable in the designer, property sheet and it renders fine on the page. Then all of a sudden it fails with a property assignment error like above. The property will vary – it’s always the first custom property, so if shuffle a different custom property to be first that property will show up as the error property.

If I remove all custom properties then the control renders again.

In this case the Draggable property is just a plain property with a private field backing.

/// <summary>
/// Determines whether this control is draggable
/// </summary>
[Description("Determines whether this control is draggable")]
[DefaultValue("true"), Category("Dragging")]
public bool Draggable
{
    get { return _Draggable; }
    set { _Draggable = value; }
}
private bool _Draggable = true;

Nothing that could possibly go wrong in assignment. There’s some OnInit() code but it’s bracketed out for designmode:

protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);

     
     if (!this.DesignMode)
     {
         this.ScriptProxy = ClientScriptProxy.Current;

         // *** Use ScriptProxy to load jQuery and ww.Jquery
         ScriptProxy.LoadControlScript(this, this.jQueryScriptLocation, ControlResources.JQUERY_SCRIPT_RESOURCE, ScriptRenderModes.HeaderTop);
         ScriptProxy.LoadControlScript(this, this.ScriptLocation, ControlResources.WWJQUERY_SCRIPT_RESOURCE);
     }
 }

This is important to avoid code that might not work at designtime because the HttpContext object doesn’t exist.

Anyway, the control works fine. In fact in the screen shot above, there there are two of the same controls on the page – the panel above is another instance of the same control type.

As I mentioned I’ve also seen similar failures with Telerik and DevExpress controls, so I don’t think it’s something that’s wrong with my controls or if it is it’s a common issue.

Unfortunately the fix for this is to restart Visual Studio. That’s right – I can’t shut down the page and re-open it; I still get the error in that case. But if I close down Visual Studio and re-open it everything is hunky dory again – until next time this sort of failure pops up again on a different control or page. Oddly if I drop another control instance on the same page that will work just fine. Freaky.

I don’t use the designer very much – typically just to drop controls onto page and in some cases to use the property editor, but even so I see this sort of error several times almost every day.

So, has anybody else seen this sort of behavior in the Web Designer? I’ve been looking around and pinging a few folks, but so far it seems this is not a common problem. Would love to hear some feedback to see if others are seeing the same, or even better if somebody has figured out a workaround or at least the cause for the issue.

Posted in Visual Studio  ASP.NET  

The Voices of Reason


 

Dave Ward
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I had the same problem when updating one of my server controls recently. Since I had been making some changes at the time, I assumed I had broken some subtle detail and agonized over fixing it for hours. Not fun.

alexandru savu
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I had this error also. Over and over again.
Stupid if you ask me. Waiting for SP 2 :)

Kieran Benton
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Unfortunately I've been bitten by this too - I'm getting increasingly concerned they're making the designer too complicated without fixing some of the underlying issues with it, its far far too easy to break!

Incidentally I also only use it for:
- Drag/dropping new controls onto the page (so that I get the correct @ register added for me)
- Creating new event handlers for controls (since you get the correct method signature created for you etc).

Don't suppose anyone knows of good ways you can achieve these without using the designer?

Bertkid
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Kieran: for the event handler creation, Resharper has a "quick fix" that will implement the method signature for you. I think it was just added in 4.0 a couple months ago, but it rocks for that purpose!

Richard
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I've seen this for the first time today, on a custom control. As with Kieran, I only use the designer for adding custom controls & event handlers. Goes away with a VS restart.

I've also got a bit annoyed with all the designer issues in SP1. My main annoyance at the moment is the massive list of "The name 'xxxx' does not exist in the current context" which goes away when you open the page it's on.

I hope both of these are released as hotfixes - don't really fancy waiting until SP2!

Daniel Crabtree
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I've encountered a very similar problem since VS2005, right through the beta's of VS2008, except beta 2, then again with VS2008 and now still with SP1 for 2008. It occurs when putting lists into a server control and assigning them values through the .aspx file. This generally results in the design view problem you're experiencing and another problem, that is far more annoying: it causes the generation of the automatically generated .designer file to fail. When forcing the rebuild of the .designer file, through the convert to webproject trick, it will complain that it cannot be built because it cannot convert an object of type A to an object of type A - replace A with any type you like. Similar to you, this problem is fixed after a somewhat strange process, deleting the offending code, recompiling, then adding the code back. From my research, others seem to have run into similar problems too. I have learned to live with it, but wish it was fixed.

Daniel Crabtree
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Not to mention an annoying SP1 only bug, which doesn't seem to affect all installs - the ListView control disappears entirely and none of the fixes suggested online that seemed to work for people using the beta of SP1, work for some installs.

Kent Merrell
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Yep, I've seen it, too. It has gone away (sometimes) when I reload the entire project. Otherwise, I just ignore it.

Rick Strahl
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Interesting to see how many people are saying - "I only use the designer to drop controls". I guess I'm not the only one who's completely lost faith and patience with the Web designer in Visual Studio. The new editor is nice in some ways (better rendering, faster operation) but stability has taken a serious hit (then again the 2005 designer was no picnic either).

I appreciate the feedback - honestly I wasn't sure whether this problem was isolated to me or not but it appears this is more universal. Honestly I don't think this is a problem with control design but something related to the designer hosting of these controls. The problem doesn't occur on stock controls but certainly on a wide variety of custom controls. For me at least those controls used to work fine prior to the SP1 update so I think this is a new problem.

@Kieran - As to adding event handlers: I use a CodeRush macro to create event handlers for me:

protected void «Caret»«Field(handlerName)»«BlockAnchor»(object sender, EventArgs e)
{
    «Marker»
}


which makes it real easy to create an event handler anywhere in code. You can rig up something similar with a CodeSnippet without any third party tools as well and I think this will be a worthwhile excercise for you. But I too wish that there was an easier way to hook up an event handler from only markup. It does work but only AFTER the designer has been activated at least once.

Mike Gale
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

From the start of VS.NET I've avoided the designers. As soon as I saw what they did to the underlying code I adopted a simple philosophy, much of the time.

1) Find all defaults that invoke designers and disable them.
2) If using a designer I unleash it on a dummy page, see what it does, then implement that same code in the real page.
3) For some jobs I have code generators that given a "list of parameter sets" produce the chunks of code needed.

This probably saves time because I don't need to fix up coding that I can't live with before release. It certainly allows me to feel more relaxed.

For test out / pathfinder projects, that get thrown away, I might relax the rules.

The more recent versions of VS are a lot better than the original, but the early horrors will never be forgotten.

I find that WYSIWYG tools tend to be YGAM tools (you get a mess), often enough to matter. For a really simple example just look at the horrible things that a CMS tool can do clean XHTML. Multiply nested divs, paragraphs or whatever are common. Then somebody asks you why it looks so odd, AND IS UNEDITABLE. Coding tools have the same sort of flaws. (And a side effect is that they can keep you ignorant of what's going on!)

This isn't necessary. I've seen these things done well. Maybe some of the coders aren't aware what the result ought to look like.

Lucas Goodwin
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

@Kieran Benton, et all

For dropping controls we just do this in the mark-up view. I never use the designer view other then when using Telerik controls and their property windows. Even then, you can usually do everything from the "Property" view and not go into designer as well.

For events, VS actually has this built in for you, though Resharper or CodeRush may be faster/easier to use. In source view there are two drop downs just below that tabs. One of those (the right one I believe) contains a list of all events for a control, page, etc. Just select it from the list and VS inserts the handler. Note that these menus are context sensitive based on where your curser is in the source.

Rick Strahl
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

@Mike - I agree with most things. However I build controls for others to use and yes for getting started with new components the designer can be a big help. I just as soon avoid the designer too but there are some things that are much easier to do WITH the designer:

* Extender properties - I have 3 different controls I use frequently that are extenders. Without designer support doing this sucks because you end up completely disconnected from the control you're extending.

* Getting first controls onto the page so that required @Register tags get loaded

* Some third party controls that provide Designer Extensions obviously can make life much easier than using markup.

All of these apply mostly to custom and third party controls. But I do find that from time to time I need to use them and if it helps I'd sure like to take advantage it.

@Lucas - How do you get the Property view to work without activating the designer? If I open a page in markup only view for ANY CUSTOM control I get nothing in the property window until I open designer - then it works. It also works with the stock controls without designer activation. Hmmm... just checked this out again now and I notice that it DOES work - sometimes. Inconsistent as heck. First access I get a blank property window, but then after a few clicks around controls of the markup it does show. Weird. One thing though you don't get an event tab either way. Extenders also don't work in this scenario unfortunately. <shrug>

David Kean
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Have you tried changing DefaultValue("true") to DefaultValue(true)?

Rick Strahl
September 18, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

@David - thanks didn't notice that, but it really shouldn't matter. Controls use type converters if the value supplied is a string so "True" should parse too. And it does work most of the time - if there was a problem with type conversion we'd see the errors all the time.

Changed it anyway though - I prefer the raw type too.

Tim
September 19, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Oh yeah, trust me, i've had it over and over again, spend hours debugging my control figuring that i did something wrong...

Lost faith in the designer long time ago!!!

Cassio R Eskelsen
September 19, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

<i>"Oh yeah, trust me, i've had it over and over again, spend hours debugging my control figuring that i did something wrong..."<i>

Me too! Now, i'm not feel alone anymore!

Joshua Starr
September 19, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I have experienced this quite a bit as well. It's kind of curious that it hasn't really been addressed via a patch yet, since it's been happening for quite a long time now. I also occasionally have VS 2008 completely bomb on me -- that's really fun when I'm in a groove, and not saving as I write :(

Pamela Thalacker
September 22, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I run into this all the time. Not even with custom controls. Most recently I have had lots of trouble with a native listview sitting under a custom control.

Like you I rarely work in design mode. Often design mode doesn't render the page anywhere close to what it looks like in the browser. I even drop controls onto my pages in source view. It works just fine most of the time. The only time I go into design mode is to set properties in the properties window or to use one of the wizards (which can sometimes save a lot of typing).

I can usually get the property window to work by putting the cursor over the object name so that it turns black in Source View. It doesn't always work, but usually the correct object will be selected in the Properties window.

pamela

Pamela Thalacker
September 22, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Ironically, just after my post here, I went to change the title for a CreateUserWizardStep and there is no way I can access the property in the designer. After restarting Visual Studio the CreateUserWizard control finally displayed in the design view, but when I click on the arrow to access the step configuration dialogs, the only option is to "Default to Master's Content" which would wipe out my native control. So I have to go to MSDN and look up the properties for the CreateUserWizardStep class and set it in code (Intellisense is very helpful once you know which property you need to set)

I just don't have any need for the designer at all. With the built-in localhost web server, it is much faster and less frustrating to just View in Browser.

pamela

Dan
September 22, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Rick,

I have been pulling my hair over this exact same problem in VS2008 SP1. I never had this problem with custom controls before. It's all the more frustrating since I use some customized container/panel controls, which means that whole parts of my content are completely out of reach except through the source view.

I spent a couple of days trying to figure out a pattern and solution to this issue but did not find any. I decimated my custom controls to try to diagnose this, and, just when I thought they were working, they would stop rendering again.

So now I no longer use the designer when I have custom or user controls. I hope Microsoft issues a fix soon because I really like the ability to visualize my page and this is irritating.

Dan

rekna
September 29, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Same problem... the bug is registered on Microsoft Connect (https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361826)

I've added my confirmation of the bug to increase the confirmation counter, I would suggest doing the same, so this bug gets more attention from microsoft and hopefully we'll get a fix soon...

rkirby
November 11, 2008

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I first saw this problem when I went to vs2008 sp1. I deleted the 3 AJAX extender controls from the toolbox and the problem went away. I had to do something. My page at design time was a just a real mess. I haven't had time to track the problem down, but this has certainly taken are of it.

Sampath Dassanayake
May 08, 2009

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Guess what? This error is now coming up on AJAX extensions as well. What are they doing? Deciding that we should not be using AJAX which is basically a MS product itself?

BruceShining
June 01, 2009

# re: ASP.NET Designer Control Problem in VS 2008 SP1

I am having a similar, more-serious, and I think related problem that I have seen elsewhere.
In my case, after installing VS2008 SP1, all controls are disabled!!
I can see them only by clicking the "Show All" option in the Toolbox context menu,
but they are greyed out and I cannot use them.

This is crazy bad!

I uninstalled SP1 and problem went away.
I reinstalled it and it's back.

grrrrrrrrrrr...

Jonathan
November 10, 2009

# re: ASP.NET Designer Control Problem in VS 2008 SP1

very, very frustrating. why don't they make these things more dev/user friendly?

Chuck
March 18, 2010

# re: ASP.NET Designer Control Problem in VS 2008 SP1

Sorry, I accidentially hit return and may have uploaded a partial comment earlier. To finish my previous rant, er.. comment... the DropDownList will show up in debug mode on the Locals window under the tree item "this". However, is you try to reference it in code behind, you will get the error message: "Named control nnnnnn does not exist in the current context"!

MS hasnt owned up to this one yet as far as I can find.

Oh, and no matter how many successful builds I did, the error always came back. I tried building with the control in the markup and without references in the code behind, deleting it all and rebuilding, all kinds of scenario's ad nauseum.

So that just leads you to a workaround which is to use FindControl to get a reference to it and cast it to a local protected variable of that same type. However, you must use the id name found in the control tree and not the ID you used in the markup. Keep in mind that DropDownList1 becomes ctl00$Main$DropDownList1 at runtime. (or something like it depending upon master pages, etc....)

To get the runtime ID, set the markup directive Trace="true" to get the control tree output at the bottom of the page in question. Copy and paste the id into the FindControl argument and you have it. The trace output will look something like this:

ctl00$Main$ctl02 System.Web.UI.ResourceBasedLiteralControl 323 0 0
ctl00$Main$DropDownList1 System.Web.UI.WebControls.DropDownList 436 216 0
ctl00$Main$ctl03 System.Web.UI.LiteralControl 152 0 0
ctl00$Main$lblcourtHouseName System.Web.UI.WebControls.Label 188 0


Depending upon your comfort level with which control it is going to find, you may want to do a little checking on it first before using the casted control, so check the type and do you due-diligence.

Here's the code:

public partial class Default_aspx  : System.Web.UI.Page
{
 
    protected DropDownList myDropDownListFix;
 
 
    protected void Page_Load( object sender, EventArgs e )
    {
        //  get a reference to the desired control
        Control myControl = FindControl("ctl00$Main$DropDownList1");
 
        //  make sure you have the right type       
        if (myControl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
        {
            // now safe to cast it to the one you want and work with it
            myDropDownListFix = (DropDownList)FindControl("ctl00$Main$DropDownList1");
            myDropDownListFix.Items.Add("Me");
            myDropDownListFix.Items.Add("You");
            myDropDownListFix.Items.Add("Calib");
            myDropDownListFix.Items.Add("The Horses");
        }
.
.
.
.


I'm sure there are more elegant ways to do this, but it is a *workaround*.
BTW, after I did the manual fix, it all started working again. So, I'm not sure whether to take the workaround out or not. Not real dependable there MS.....VS200x gotta love it. Definitely a love-hate relationship.

I know this doesnt address any event handler problems you may have when you dont have visibility to the control. If I wind up in visibilty purgatory again, I will post the fix here, friends.
But for now it started working. Not LOL.
Cheers.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024