How to hide property of ASP.NET custom control in aspx page?
Asked Answered
M

2

7

I'm writing ASP.NET custom control, and I want it to have a few properties which should be visible only from code behind during run-time - I mean, these properties should not be visible both in a designer and in a aspx code of page containing this control. I've tried to use following attributes:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public List<Item> SomeData { ... }

but unfortunately this property is still visible in an Intellisense combobox when editing aspx page. Is it possible to hide this property everywhere besides server-side code ?

Mathis answered 8/2, 2010 at 10:59 Comment(0)
Q
12

This should do the trick:

//Hide from Designer Property Grid
[Browsable(false)]
// Hide from VS.NET Code Editor IntelliSense
[EditorBrowsable(EditorBrowsableState.Never)]
// Not Serialized in Designer Source code "HTML view"
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public List<Item> SomeData { ... }
Quittor answered 22/11, 2010 at 5:41 Comment(0)
T
2

Amiir's answer definitely works, but I'd like to add that sometimes even after applying the attributes, the Intellisense still displays the properties. This is a result of Visual Studio caching the Intellisense files. If you build the same project on a different machine, it will not show the properties. If this really bugs you, you can clear the cache by deleting all files in the folder "C:\Documents and Settings\[YOUR_USER_NAME]\Application Data\Microsoft\VisualStudio\10.0\ReflectedSchemas."

Tessatessellate answered 3/3, 2011 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.