Correct Pattern for creating Server Controls?

36 Views Asked by At

I am creating a server control (inheriting from CompositeControl).

The control comprises of several data bound drop down lists (and some textboxes etc).

The drop down lists form a hierarchy, so are dependent on each other... eg

ddlCountry

-ddlCounty

--ddlCity

When ddlCountry is selected, this should refresh the list of ddlCounty... and so on with the ddlCity etc.

I would like to access the value of the ddlCountry within the control, so I can set the data source for second ddl (ddlCounty) accordingly, but in CreateChildControls() the viewstate does not seem to have loaded the ddlCountry user selection yet into the control, so I get an empty string.

I also need to provide these ddl values as a public property.

This is getting quite messy, with the use of ReCreateChildControls() etc... which I'm sure is wrong.

My Question: Can anyone suggest the correct pattern / set of rules to abide by to create this server control

eg

  1. initialise controls OnInit
  2. DataBind on OnLoad
  3. Put EnsureChildControls() at beginning of any property: get or set

I assume there must be a correct way of implementing this, but cannot find any documentation or example to get this working as you would expect of a standard control.

Thanks

0

There are 0 best solutions below