Question

I have created a UserControl that has a ListView in it. The ListView is publicly accessible though a property. When I put the UserControl in a form and try to design the ListView though the property, the ListView stays that way until I compile again and it reverts back to the default state.

How do I get my design changes to stick for the ListView?

Was it helpful?

Solution

You need to decorate the ListView property with the DesignerSerializationVisibility attribute, like so:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ListView MyListView { get { return this.listView1; } }

This tells the designer's code generator to output code for it.

OTHER TIPS

Fredrik is right, basically, when you need to enable the designer to persist the property to page so it can be instantiated at run time. There is only one way to do this, and that is to write its values to the ASPX page, which is then picked up by the runtime.

Otherwise, the control will simply revert to its default state each and every time.

Always keep in the back of your mind that the Page (and its contents) and the code are completely seperate in ASP.NET, they are hooked up at run time. This means that you dont get the nice code-behind designer support like you do in a WinForms app (where the form is an instance of an object).

Just so I'm clear, you've done something like this, right?

public ListView MyListView { get { return this.listView1; } }

So then you are accessing (at design time) the MyListView property on your UserControl?

I think if you want proper design-time support you're better off changing the "Modifier" property on the ListView itself (back on the original UserControl) to Public - that way you can modify the ListView directly on instances of the UserControl. I've had success doing that anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top