ASP.NET Designer Control Problem in VS 2008 SP1
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:
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.
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
- Getting the ASP.NET Core Server Hosting Urls at Startup and in Requests
The Voices of Reason
# re: ASP.NET Designer Control Problem in VS 2008 SP1
Stupid if you ask me. Waiting for SP 2 :)
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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?
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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!
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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.
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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.
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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.
# re: ASP.NET Designer Control Problem in VS 2008 SP1
* 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>
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
Changed it anyway though - I prefer the raw type too.
# re: ASP.NET Designer Control Problem in VS 2008 SP1
Lost faith in the designer long time ago!!!
# re: ASP.NET Designer Control Problem in VS 2008 SP1
Me too! Now, i'm not feel alone anymore!
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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...
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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...
# re: ASP.NET Designer Control Problem in VS 2008 SP1
# re: ASP.NET Designer Control Problem in VS 2008 SP1
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.
# re: ASP.NET Designer Control Problem in VS 2008 SP1