How to allow my control contains a text inside it's tags?
<uc:My runat="server">Text</uc:My>
My control contains a complex table and I want to put Text into one of cells. How to do that?
How to allow my control contains a text inside it's tags?
<uc:My runat="server">Text</uc:My>
My control contains a complex table and I want to put Text into one of cells. How to do that?
Maybe this post will get you started: http://stackoverflow.com/questions/604620/is-there-a-way-to-put-inner-controls-inside-a-asp-net-custom-control
Have a property on your user control called Text
, and set that like
<uc:My id="my" Text="some text" runat="server">Text</uc:My>
or server side
my.Text = "some text";
Assuming the UC generates a table, the easiest method I can think of is this:
In the UserControl's ascx do something like this:
<table>
<tr>
....
<td><asp:Literal runat="server" ID="ltCellContent" /></td>
....
</tr>
</table>
In the UserControl's code behind:
public string CellContent
{
get { return ltCellContent.Text; }
set { ltCellContent.Text = value; } }
}
And to use it:
<uc:My runat="server" CellContent="Some content" />
[PersistChildren(false)]
[ParseChildren(true, "Text")]
public partial class RequiredFieldMarker : UserControl, ITextControl
{
[Category("Settings")]
[PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
public string Text
{
get
{
return lblName.Text;
}
set
{
lblName.Text = value;
}
}