Hide User-Control in Design Mode

末鹿安然 提交于 2019-12-12 02:15:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!