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(SubObj ectType Type): base(HtmlTextWr iterTag.Div)
{
_Type = Type;
}
public MyObject(): base(HtmlTextWr iterTag.Div)
{
_Type = SubObjectType.F oo;
}
private SubObjectType _Type;
public string BuriedText
{
set
{
EnsureChildCont rols();
Control Sub = (Control) Controls[0];
Sub.Text = value;
}
}
override protected void CreateChildCont rols()
{
switch(_Type)
{
case SubObjectType.F oo:
{
FooControl Ctrl = new Myspace.FooCont rol();
Controls.Add(Ct rl)
}
case SubObjectType.B ar:
{
BarControl Ctrl = new Myspace.BarCont rol();
Controls.Add(Ct rl)
}
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:myobje ct id="myobject1" type="bar" buriedtext="hel lo" />
the Type property is set before the BuriedText property. So when
CreateChildCont rols is executed, the correct subcontrol is created.
However, if I swap the order, as in:
<myspace:myobje ct id="myobject1" buriedtext="hel lo" type="bar" />
CreateChildCont rols 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:myobje ct(bar) id="myobject1" buriedtext="hel lo" />
Any ideas?
Thanks.
--Tad
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(SubObj ectType Type): base(HtmlTextWr iterTag.Div)
{
_Type = Type;
}
public MyObject(): base(HtmlTextWr iterTag.Div)
{
_Type = SubObjectType.F oo;
}
private SubObjectType _Type;
public string BuriedText
{
set
{
EnsureChildCont rols();
Control Sub = (Control) Controls[0];
Sub.Text = value;
}
}
override protected void CreateChildCont rols()
{
switch(_Type)
{
case SubObjectType.F oo:
{
FooControl Ctrl = new Myspace.FooCont rol();
Controls.Add(Ct rl)
}
case SubObjectType.B ar:
{
BarControl Ctrl = new Myspace.BarCont rol();
Controls.Add(Ct rl)
}
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:myobje ct id="myobject1" type="bar" buriedtext="hel lo" />
the Type property is set before the BuriedText property. So when
CreateChildCont rols is executed, the correct subcontrol is created.
However, if I swap the order, as in:
<myspace:myobje ct id="myobject1" buriedtext="hel lo" type="bar" />
CreateChildCont rols 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:myobje ct(bar) id="myobject1" buriedtext="hel lo" />
Any ideas?
Thanks.
--Tad
Comment