开发者

User control attributes at design-time

开发者 https://www.devze.com 2022-12-23 23:06 出处:网络
I\'m testing a simple User Control in Visual Studio 2008: A Panel named Wrapper with some controls inside. C开发者_JS百科an Visual Studio handle this at design time?

I'm testing a simple User Control in Visual Studio 2008: A Panel named Wrapper with some controls inside. C开发者_JS百科an Visual Studio handle this at design time?

public partial class TestControl : System.Web.UI.UserControl
{
    [Description("Css class of the div around the control.")]
    [CssClassProperty]
    public string CssClass
    {
        get { return Wrapper.CssClass; }
        set { Wrapper.CssClass = value; }
    }
}

When setting the CssClass property, it doesn't update the css of the Panel at design time. Am I hoping for too much?


I think you would have to check the parent and cast it

if(this.Parent is Panel)
{
   ((Panel)this.Parent).CssClass = value;
}

Or similar.


Designing pages can be a big headache in the VS IDE as the IDE is unaware of CSS loaded by your ASPX when that content is loaded through code-behind or by a global page header that your entire site inherits (for example, through sub-classing of PAGE.) It makes using the VS IDE quite difficult for designing those sub-pages / controls / etc. Inserting the CSS into your sub-document or control is not an option, because the compiled page will often then include duplicate references to the style sheet, and quite possibly serving the first reference even before the declaration.

Here is one way to get Visual Studio to use arbitrary CSS in the IDE getting past this, so you can design controls using css that the designer is unaware exists in the served page. So you can use this to make CSS available at design time in the editor, but NOT at debug or run-time. I'm quite certain this will work in your scenario as well.

Insert this:

<% 
#If 0 Then
%>    
    <link rel='stylesheet' href='mycss.css' type='text/css' />        
<%
#End If
%>

This will load your style sheet only in the html designer of the IDE.

0

精彩评论

暂无评论...
验证码 换一张
取 消