[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

INamingContainer and ClientID for nested Composite Controls - Guidance needed

Greg Woods

3/19/2008 10:50:00 AM

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"
Text="SITE_INC307">
<cc:DateControl ID="EndDate" Text="ENDDATE"
format="EditNoLabel" runat="server" />
<cc:HyperlinkControl
NavigateURL="javascript:removeEndDate()" runat="server" Text="REMOVE" /
>
</cc:LabelledWrapper>
</cc:Tab>
</cc:TabControl>

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
2 Answers

Teemu Keiski

3/19/2008 12:09:00 PM

0

You can override the rendering or you can use custom helper solutions such
as IDOverride: http://www.wilcob.com/Demos/I...

Getting the ID for scripting in server-side code isn't too hard, therefore
controls have ClientID property.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice....
http://teemu...

"Greg Woods" <misternightdrive@gmail.com> wrote in message
news:65ac49ed-cb6b-4bc6-8742-24b4aaf90c9e@59g2000hsb.googlegroups.com...
>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"
> Text="SITE_INC307">
> <cc:DateControl ID="EndDate" Text="ENDDATE"
> format="EditNoLabel" runat="server" />
> <cc:HyperlinkControl
> NavigateURL="javascript:removeEndDate()" runat="server" Text="REMOVE" /
>>
> </cc:LabelledWrapper>
> </cc:Tab>
> </cc:TabControl>
>
> 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


Peter Bucher [MVP]

4/1/2008 12:00:00 PM

0

Hallo Greg

You can use a simple trick to not render ClientIDs.

-
http://translate.google.com/translate?u=http%3A%2F%2Fwww.aspnetzone.de%2Fblogs%2Fpeterbucher%2Farchive%2F2008%2F02%2F24%2Fein-webcontrol-das-keine-clientid-rendert.aspx&langpair=de%7Cen&hl=de&am...
(Translated -> Englisch)
-
http://www.aspn...blogs/peterbucher/archive/2008/02/24/ein-webcontrol-das-keine-clientid-re...
(Original)

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspn... - ASP.NET Zone, die ASP.NET Community
http://www.aspn...blogs/peterbucher/ - Auf den Spuren von .NET