0
votes

A few times I've attempted to customize a SP2007 page using css, html, or javascript in Sharepoint Designer; however, in Sharepoint Designer I am not able to get direct access to the desired elements since they are generated by a Sharepoint Control (such as a web part or dataview) and appear only AFTER the page is rendered in the browser. I use use IE's F12 to tracked the element I wish to change. Then I can see an identifer such as name or id I can use in my javascript or css.

Example 1: SP2007 generates "name=ctl00$PlaceHolderMain$g_ba9196a9_2842_4607_b048_9a443cb4def5$ff2_1$ctl00$ctl00$BooleanField" for an input text box. I use that name to manipulate the text box as I desire.

Example 2: SP2007 generates "id=zz6_menu" for the "Welcome" text which I use to get the users full name.

So far this has worked out fine. Am I tempting fate?

Can someone refer me to a reference that discusses how these names and other Sharepoint Control element identifiers are generated?

Are they stable? Can I count on them to be the same provided the application I develop with my version of SP isn't updated to a later version of SP? And even if that case I'm thinking I can simply update to the identifiers created by the newer version of SP.

Is this a good practice? Any other comments?

All responses are welcomed.

Thanks.

1

1 Answers

0
votes

SharePoint is based on ASP.NET and that's why the Ids are automatically genereated.

cf this article. You should not use them to identify elements on css or js.

Do not write code that references controls using the value of the generated UniqueID property. You can treat the UniqueID property as a handle (for example, by passing it to a process), but you should not rely on it having a specific structure.

In my opinion, the best way is to rely on the css classes because they are not automatically generated and should not change a lot.

Anyway, if you upgrade to SP2010 or 2013, lot of your modifications won't work anymore because the structure and css changed...