FOUND THE ANSWER MYSELF, see below…
I’d like to have a very simple user control…
<mw:Translate LocalizedText="Some text" />
This results in “Some text” in output.
However, if I put it like this:
<mw:Translate ID="translate1" LocalizedText="Some text" />Some other text</mw:Translate>
<mw:Translate ID="translate2"/>Some other text</mw:Translate>
ID=translate1 results in “Some text” while ID=translate2 renders “Some other text”
Simply, if the LocalizedText attribute is not set, then the text inside the translate tag is rendered. If neither LocalizedText, nor a text inside the element are set, empty string is rendered.
For clarification, LocalizedText attribute is prefered. So if the mw:Translate tag body and the LocalizedText are set, Localized Text is rendered.
I’m writting this just because I’m not sure how to set correctly the UserControl property attributes…
using System.Web.UI;
using System.ComponentModel;
using System;
namespace MagicWare.Web.UI.WebControls
{
[PersistChildren(false)]
[ParseChildren(true, "InsideText")]
public class Translate : System.Web.UI.WebControls.Literal
{
public string LocalizedText
{
get { return Text; }
set { this.Text = Translations.Translate(Value); }
}
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public string InsideText { get; set; }
protected override void Render(HtmlTextWriter writer)
{
if (!String.IsNullOrEmpty(Text))
{
writer.Write(Text);
return;
}
if (!String.IsNullOrWhiteSpace(InsideText))
{
writer.Write(InsideText);
return;
}
writer.Write("");
}
}
}
ANSWER
Everything i needed to know was the existence of the interface ITextControl. With it, I just implement a “Text” attribute, which contains the text put inside the tags so it works like the literal control.
Everything i needed to know was the existence of the interface ITextControl. With it, I just implement a “Text” attribute, which contains the text put inside the tags so it works like the literal control.