Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Composite Control with DataList setting Template / Property

Reply
Thread Tools

Composite Control with DataList setting Template / Property

 
 
berny.zamora@gmail.com
Guest
Posts: n/a
 
      05-14-2008
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
 
Reply With Quote
 
 
 
 
xAvailx
Guest
Posts: n/a
 
      05-14-2008
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, (E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Composite Control Property Setting Problem Alphonse Giambrone ASP .Net 9 07-05-2004 11:14 PM
Composite Control Property Setting Problem Alphonse Giambrone ASP .Net Building Controls 9 07-05-2004 11:14 PM



Advertisments