INamingContainer and ClientID for nested Composite Controls -Guidance needed


Greg Woods

I have created a series of Composite Controls, inheriting from
CompositeControl, which of course implements INamingContainer. Below
is a snippet of simplified code to show how I'm using these controls
in the page.
(The reason I've rolled my own tabcontrol, and why I've used my own
string translation are out of scope of this question)

<cc:TabControl ID="TabControl" runat="server">
<cc:Tab Text="SITE_INC19" ID="TabMain" runat="server">
<cc:LabelledWrapper ID="EndDateRow" runat="server"
<cc:DateControl ID="EndDate" Text="ENDDATE"
format="EditNoLabel" runat="server" />
NavigateURL="javascript:removeEndDate()" runat="server" Text="REMOVE" /</cc:LabelledWrapper>

Since I give each nested control its' own unique ID, I have no need
for the default naming of INamingContainer.

Also, considering the DateControl, which will render a textbox, I
would prefer the rendered textbox have the ID of the overall control,
in this case "EndDate", instead of
"TabControl_TabMain_EndDateRow_EndDate_EndDate_date". For the
constituent controls which make up the DateControl, I don't care what
ID they are given - in fact as they are mostly labels and such which I
never need to access using javascript, I actually have no need for
them to have a rendered ID.

The problem with the default behaviour is that it is
* not needed, as I give unique Ids where appropriate
* means i have to have server side code to determine clientIds in my
javascript, instead of being to simply set it to the id of the control
- i.e. I cannot hardcode: document.getElementById("EndDate") into a
static .js file.
* bloated html - elements - many of which have no need for any id

As I'm fairly new to .NET, and very new to creating controls, what is
my best option? Other related posts suggest stick with the official MS
way of doing it - despite the issues I mention. Do I drop the use of
CompositeControl, and add lots of 'EnsureChildControls' calls in my
code? I'm open to suggestions.

Thanks in advance

Greg Woods

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads