D
DC
Hi,
I want to keep all my layout information in the .ascx file of a
UserControl. If I require layout related data in codebehind, I would
usually use properties defined in the codebehind, e.g.
string tdStyle;
public string TdStyle
{
get { return tdStyle; }
set { tdStyle = value; }
}
and then set the property in the .ascx, like so:
<script type="text/C#" runat="server">
protected override void OnInit(EventArgs e)
{
TdStyle = "background-color:red;";
}
</script>
This also has the advantage that I could set the property TdStyle in
the .aspx file hosting the .ascx, too.
However, I dislike overriding OnInit in the .ascx (ideally I want to
keep as much code out from that file as possible) just to set some
properties. An alternative approach is using literals like
<asp:Literal ID="TdStyle" runat="server"
Visible="false">background-color:red;</asp:Literal>
but here I need to define a control for every property and the property
data is always a string. Too much overhead.
I was wandering, if someone knows a more elegant approach.
Regards
DC
I want to keep all my layout information in the .ascx file of a
UserControl. If I require layout related data in codebehind, I would
usually use properties defined in the codebehind, e.g.
string tdStyle;
public string TdStyle
{
get { return tdStyle; }
set { tdStyle = value; }
}
and then set the property in the .ascx, like so:
<script type="text/C#" runat="server">
protected override void OnInit(EventArgs e)
{
TdStyle = "background-color:red;";
}
</script>
This also has the advantage that I could set the property TdStyle in
the .aspx file hosting the .ascx, too.
However, I dislike overriding OnInit in the .ascx (ideally I want to
keep as much code out from that file as possible) just to set some
properties. An alternative approach is using literals like
<asp:Literal ID="TdStyle" runat="server"
Visible="false">background-color:red;</asp:Literal>
but here I need to define a control for every property and the property
data is always a string. Too much overhead.
I was wandering, if someone knows a more elegant approach.
Regards
DC