Forcing constructor from aspx

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tadrichard@nc.rr.com

    #1

    Forcing constructor from aspx

    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

  • TadRichard

    #2
    RE: Forcing constructor from aspx

    Could an administrator (or MVP if you are able) please remove this thread? I
    mistakenly submitted it with my email address and I'd like to minimize the
    spam I receive as a result.

    Thanks
    --Tad

    Comment

    • Jon Skeet [C# MVP]

      #3
      RE: Forcing constructor from aspx

      TadRichard <TadRichard@dis cussions.micros oft.com> wrote:[color=blue]
      > Could an administrator (or MVP if you are able) please remove this thread? I
      > mistakenly submitted it with my email address and I'd like to minimize the
      > spam I receive as a result.[/color]

      I'm afraid even if it could be done at this stage - and MVPs don't have
      access - the way things work these days, your post will be on various
      mirroring websites etc by now.

      (Personally I find it better just to use my real email address
      everywhere and just deal with spam. YMMV.)

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      Working...