Composite Control with DataList setting Template / Property

Discussion in 'ASP .Net' started by berny.zamora@gmail.com, May 14, 2008.

  1. Guest

    Hello everyone,

    I have a composite control (lets call it the parent) that contains a
    datalist. The datalist has an ItemTemplate that contains another
    composite control (lets call it the child). I am trying to create a
    property at the parent control that sets a property in the child
    instances.

    So for example lets say I am creating a control that displays a list
    of hotel reservations for a group of people.

    Hierarchy:

    HotelControl (CompositeControl)
    --DataList
    ----ItemTemplate
    ------ReservationInfoControl (CompositeControl)

    I want a property for the HotelControl that sets a property for the
    ReservationInfoControl instances.

    For example.

    myHotelControl.ShowDatesAsDropdown = true;

    This property controls whether the child instances will show dates as
    a dropdown, otherwise it should show as a "calendar". I set this
    property on the page's PageLoad event.

    The Problem
    ------------------
    I have tried creating a constructor for the ItemTemplate that takes in
    the property from the parent control "OnInit". The problem is OnInit
    fires before my property is set. I have also tried creating a property
    in HotelControl that takes in the ItemTemplate, but have the same
    timing issue.

    If I set my property on the page's PreInit, it works, but that is not
    the standard behavior of other asp.net controls.

    So my question is, are there any examples with what I am trying to do?
    It sounds like a fairly standard problem, but I just can't find which
    Event to set my properties in. My second thought was to Recreate the
    child controls when the property is set but that seemed hackish.

    Any ideas / examples?

    Thx, BZ
    , May 14, 2008
    #1
    1. Advertising

  2. xAvailx Guest

    I found another way of doing this...

    I know reset the datalist's item template on property set in the
    parent control. For example:

    set {
    EnsureChildControls();

    ViewState["ShowDatesAsDropdown"] = value;

    //update item template
    MyItemTemplate itemTemplate = new MyItemTemplate(value);
    mDataList.ItemTemplate = itemTemplate;
    }

    That seems to work and can now set the property in PageLoad.

    Is this the standard way to handle this scenario?

    Thx.

    On May 14, 10:35 am, wrote:
    > Hello everyone,
    >
    > I have a composite control (lets call it the parent) that contains a
    > datalist. The datalist has an ItemTemplate that contains another
    > composite control (lets call it the child). I am trying to create a
    > property at the parent control that sets a property in the child
    > instances.
    >
    > So for example lets say I am creating a control that displays a list
    > of hotel reservations for a group of people.
    >
    > Hierarchy:
    >
    > HotelControl (CompositeControl)
    > --DataList
    > ----ItemTemplate
    > ------ReservationInfoControl (CompositeControl)
    >
    > I want a property for the HotelControl that sets a property for the
    > ReservationInfoControl instances.
    >
    > For example.
    >
    > myHotelControl.ShowDatesAsDropdown = true;
    >
    > This property controls whether the child instances will show dates as
    > a dropdown, otherwise it should show as a "calendar". I set this
    > property on the page's PageLoad event.
    >
    > The Problem
    > ------------------
    > I have tried creating a constructor for the ItemTemplate that takes in
    > the property from the parent control "OnInit". The problem is OnInit
    > fires before my property is set. I have also tried creating a property
    > in HotelControl that takes in the ItemTemplate, but have the same
    > timing issue.
    >
    > If I set my property on the page's PreInit, it works, but that is not
    > the standard behavior of other asp.net controls.
    >
    > So my question is, are there any examples with what I am trying to do?
    > It sounds like a fairly standard problem, but I just can't find which
    > Event to set my properties in. My second thought was to Recreate the
    > child controls when the property is set but that seemed hackish.
    >
    > Any ideas / examples?
    >
    > Thx, BZ
    xAvailx, May 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,674
    sleigh
    Feb 12, 2004
  2. Alphonse Giambrone

    Composite Control Property Setting Problem

    Alphonse Giambrone, Jul 3, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    1,757
    MS News \(MS ILM\)
    Jul 6, 2004
  3. Nevyn Twyll
    Replies:
    8
    Views:
    1,847
  4. Alphonse Giambrone

    Composite Control Property Setting Problem

    Alphonse Giambrone, Jul 3, 2004, in forum: ASP .Net Building Controls
    Replies:
    9
    Views:
    195
    MS News \(MS ILM\)
    Jul 6, 2004
  5. Chad
    Replies:
    0
    Views:
    211
Loading...

Share This Page