Set default properties for ASP.Net controls

118 views Asked by At

How would I set the default properties of server controls that I'll always use? For example I have combos all over my pages which almost always look the same in the mark up text (e.g. CSS CLasses for PopUp, TextBox, Button, etc.)

I thought of putting the control inside an user control and set the properties there. But then I would have to access the control itself with a property of the UC.

I want to get rid of these repeating tags:

        <Appearance>
            <AnyRecordFieldCell CssClass="SFGridAnyRecord"></AnyRecordFieldCell>
            <AlternateRecordFieldCell CssClass="SFGridAlternateRecord"></AlternateRecordFieldCell>
            <RecordPreviewCell CssClass="SFGridRecordPreview" />
            <GroupIndentCell CssClass="SFGridGroupIndentCell" />
            <GroupCaptionCell CssClass="SFGridGroupCaption" />
            <AnySummaryCell CssClass="SFGridAnySummary" />
            <GroupCaptionPlusMinusCell CssClass="SFGridPlusMinus" />
            <TopLeftHeaderCell CssClass="SFGridTopLeftHeaderCell" />
            <RowHeaderCell CssClass="SFGridRowHeaders" />
            <ColumnHeaderCell CssClass="SFGridColumnHeaders" />
            <GroupHeaderRowHeaderCell CssClass="SFGridGroupedColumnHeaders" />
            <FilterBarCell CssClass="SFGridFilterBarCell" />
        </Appearance>

Any ideas?

2

There are 2 answers

1
Alex On

Consider using ASP.NET Themes, you can use them to set mark-up for controls.

2
Joe Ratzer On

You could go with a purely CSS solution if these elements are almost always the same - i.e. have styles for input and button elements.

Where styles differ the enclosing div, for example, can be referenced to change the style.