Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs
Contact   •   Articles   •   Products   •   Support   •   Search
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX, PPT, PDF, images and more

Properties getting mixed up in VS 2005 ASP.NET Visual Designer


:P
On this page:

Here's an interesting problem in the ASP.NET designer in VS 2005: I have a custom control that has two properties with similar names. Somehow Visual Studio's designer appears to be getting the properties mixed up when trying to display the properties in the property sheet.

Here are the property definitions on a custom control:

/// <summary>
/// The CSS class that is used to render a selected button. Defaults to selectedtabbutton.
/// </summary>
[Browsable(true),
 Description("The CSS style used for the selected tab"),
 DefaultValue("selectedtabbutton")]
public string SelectedTabCssClass 
{
    get { return this._SelectedTabCssClass; }
    set { this._SelectedTabCssClass = value; }
}
string _SelectedTabCssClass = "selectedtabbutton";

/// <summary>
/// The Selected Tab. Set this to the TabPageClientId of the tab that you want to have selected
/// </summary>
[Browsable(true),
Description("The TabPageClientId of the selected tab. This TabPageClientId must map to TabPageClientId assigned to a tab. Should also match an ID tag in the doc that is shown or hidden when tab is activated."),
DefaultValue("")]
public string SelectedTab 
{
    get { return this._SelectedTab; }
    set { this._SelectedTab = value; }
}
string _SelectedTab = "";

Now in the designer in VS in markup I have:

       <ww:wwWebTabControl ID="MyTabControl" runat="server" SelectedTab="divPostBack">
       </ww:wwWebTabControl>

But when I pull up the property sheet I get:

Somehow the designer managed to assign the SelectedTab value to SelectedTabCssClass and it munges up the CSS display in this case in what the designer displays.

Even worse though is that if I reset the properties to their defaults and then explicitly enter a new value for SelectedTab it writes out the value correctly to markup. But when I return back to the visual designer once again the values are hosed. It doesn't even work if two separate and non-default values are assigned to the properties.

This is really odd - I'm thinking I must be doing something wrong here because surely I've had other controls with similar names like this but I can't see what could be hosing this up...

But what could VS really be doing to get this wrong? It would appear that it uses Reflection to get the properties from the control - what could possibly cause Reflection to get confused by similar names - it's almost like the comparison cuts off after a certain set of characters.

[somewhat later]

So after once again fretting over a problem like this for quite a bit of time it turned out the issue was one of having to restart Visual Studio. I know, I know I should do this much sooner, but heck how often do I have to restart to ensure that VS is not on the fritz?

I found this when I finally decided to use the debugger to see what's actually accessing the wrong property in the property get and as soon as I launched the debugged session in a separate process the problem of course went away.

But that still begs the question: What the heck could possibly cause VS and Reflection to mix up properties like this? Those funky 'Refresh' assemblies (and I did delete those and the original assemblies to ensure a new batch was definitely loaded)?

<shrug> Chalk that one up to the reminders: When in doubt restart <s>...

Posted in ASP.NET  Visual Studio  

The Voices of Reason


 

# DotNetSlackers: Properties getting mixed up in VS 2005 ASP.NET Visual Designer


Steve from Pleasant Hill
June 12, 2007

# re: Properties getting mixed up in VS 2005 ASP.NET Visual Designer

Long is the list of common ills cured by a daily re-boot.
 

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