User Control custom properties lose state when user control is rebuilt?

The problem is that the DefaultValueAttribute only tells the designer what the default value is for the property. It controls whether the property is displayed in bold and what the value gets reset to when you right-click on the property and choose "Reset" from the context menu.

The problem is that the DefaultValueAttribute only tells the designer what the default value is for the property. It controls whether the property is displayed in bold, and what the value gets reset to when you right-click on the property and choose "Reset" from the context menu. What it doesn't do is set the property to a particular value at run-time.To do that, you'll need to place code in your user control's constructor method.

For example: // set default visibility this.removeButton. Visible = true; Otherwise, as you've described, the value of the property will be reset when you rebuild the project.It will show up in bold in the Properties window of the designer, because it doesn't match the default (as specified in the DefaultValueAttribute), but that attribute doesn't change what the value is set to.

I tried the above and set "this.removeButton. Visible = true" in the user control's constructor. Initially it appeared to keep its state.

Rebuilds without changes did not change the property value. However, when I made a change to the user control and rebuilt it, again the property switched to "false" and became bold. This is quite annoying.

– Elan Apr 13 at 15:01 @Elan: Then there has to be something in your code that's changing the value. I've created a number of reusable control libraries and user controls, but I've never had a problem with this. Do a search in your code to see if you have anywhere setting the removeButton.

Visible property. It's likely hidden in the *.Designer. Cs file where it was automatically inserted and you can't see it.

– Cody Gray Apr 14 at 5:00 The user control sets property to "true" in constructor. The designer. Cs of the main form is code generating "ShowRemoveButton" property to false.

Those are the only two places. I removed the DefaultValue(true) attribute on the property declaration on the user control in the hopes that setting the property on the main form to "true" would cause the value to stick. Yet, the property value of "true" is lost when the designer.Cs class is regenerated and is replaced with "false".

I cannot get the "true" value to stick. This occurs after some form designer changes and rebuilding. – Elan Apr 14 at 16:12 @Elan: If you can reliably reproduce this, please consider editing your question to include the minimum code required for others to do so.

I think I understand what you're saying, but I haven't seen this behavior before in my own use. I know there are some edge cases where Visual Studio's Designer will bork things up, but I'm interested in investigating as many of those as possible. If I can reproduce it myself, I can either get you a fix, or get a bug report filed with Microsoft and link to it here for others to confirm.

– Cody Gray Apr 14 at 23:32 Thanks, I will attempt to isolate the minimum amount of code required to reproduce and will post it. I will need a couple of days to get back to you on this. – Elan Apr 131 at 13:37.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions