Is there any way in ASP.Net (1.1) to force a parameterized constructor
of an object from the server tag in the ASPX code? Alternatively, if
there any way to force the IDE to render tag properties in a specific
order?
For instance, let's say I have the following code for a custom server
control:
namespace Myspace
{
public class MyObject : WebControl
{
public MyObject(SubObjectType Type): base(HtmlTextWriterTag.Div)
{
_Type = Type;
}
public MyObject(): base(HtmlTextWriterTag.Div)
{
_Type = SubObjectType.Foo;
}
private SubObjectType _Type;
public string BuriedText
{
set
{
EnsureChildControls();
Control Sub = (Control) Controls[0];
Sub.Text = value;
}
}
override protected void CreateChildControls()
{
switch(_Type)
{
case SubObjectType.Foo:
{
FooControl Ctrl = new Myspace.FooControl();
Controls.Add(Ctrl)
}
case SubObjectType.Bar:
{
BarControl Ctrl = new Myspace.BarControl();
Controls.Add(Ctrl)
}
default:
break;
}
}
}
}
I want to pass "Bar" as the SubObjectType using a server tag in the
ASPX code. If I put the "type=" parameter BEFORE the "buriedtext="
parameter as in:
<myspace:myobject id="myobject1" type="bar" buriedtext="hello" />
the Type property is set before the BuriedText property. So when
CreateChildControls is executed, the correct subcontrol is created.
However, if I swap the order, as in:
<myspace:myobject id="myobject1" buriedtext="hello" type="bar" />
CreateChildControls is executed before the Type is set and I'm hosed.
I can work around this by editing all the server tags, but Visual
Studio likes to rearrange them again on me any time I edit a property.
What I'd really like is to do something like:
<myspace:myobject(bar) id="myobject1" buriedtext="hello" />
Any ideas?
Thanks.
--Tad