Quote:
public Label c
{
...
set { c = value as Label; }
}
A classic example of infinite recursion. :)
You set
c
to something, which calls the setter for
c
, which calls the setter for
c
, which calls the setter for
c
, which calls...
Eventually, you'll get, not an "explosion", but a
StackOverflowException
. Which is
almost always caused by infinite recursion.
You're going to need to split this into two properties: one of type
Label
, which can be set from the code-behind; and another of type
string
, which can be set to the label's ID from the markup:
[TypeConverter(typeof(ControlIDConverter))]
[IDReferenceProperty]
public string LabelMainID
{
get { return (string)ViewState["LabelMainID"] ?? string.Empty; }
set { ViewState["LabelMainID"] = value; }
}
public Label LabelMain
{
get
{
string id = LabelMainID;
if (string.IsNullOrEmpty(id)) return null;
return NamingContainer.FindControl(id) as Label;
}
set
{
if (value == null)
{
LabelMainID = null;
}
else
{
LabelMainID = value.ID;
}
}
}