问题
Controls in my ASP.Net (3.5) pages to simulate popups (Visual-Studio 2008).
The problem is that all these popups are positioned over the normal controls in the page in design mode.
So my Question is: How can I hide User-Controls in Design-Mode.
回答1:
From googling around a bit I don't think you can with an ascx. I think you should turn it into a custom control if you need this.
http://www.west-wind.com/WebLog/posts/189.aspx might help
edit: http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/
you might be able to do this if you create a custom control that holds an instance of your user control, and uses the method linked to above to hide all its content.
回答2:
If you are using a usercontrol you can take advantage of the fact the designer ignores your code. I got the following to work:
create two styles in your user control:
<style type="text/css">
.hide
{
display:none;
}
.show
{
display:;
}
</style>
create two asp panels in your usercontrol:
<asp:Panel ID="pnlDesigner" runat="server" CssClass="show">
Put content you want to show in designer here
</asp:Panel>
<asp:Panel ID="pnlDisplay" runat="server" CssClass="hide">
Put all your actual content here
</asp:Panel>
add this to your code:
protected override void OnPreRender(EventArgs e)
{
pnlDisplay.CssClass = "show";
pnlDesigner.CssClass = "hide";
base.OnPreRender(e);
}
For me this creates the desired effect of having a small block of text render in the designer for my user control
来源:https://stackoverflow.com/questions/1781944/hide-user-control-in-design-mode