I think a static member is the only way to do this, unless you want to do it in the parent page's class, which I don't think you want to do.
It all comes down to timing I think. When do you want your controls to know how many others are on the page? Obviously each time you increment the control counter, it will only know about the controls on the page so far.
If you do it in one of the Page's events, like maybe Page.PreRender, you can then put something like...
TotalMyControls = Page.NumberOfMyControls
into the Control.SaveViewState event handler.
Yes, then your control is dependent on the Page, but you can always overload the page class, or use a master page.
HTH
Aaron
|