JQuery, Content Placeholders & CSS ID's

JQuery, Content Placeholders & CSS ID's

Hi All,

I am building an ASP.net webpage using JQuery portlets.

Everything seemed to be working great when constructing my test page (The portlets could be dragged-and-dropped around the page, and I had an update function writing their locations to a backend database).

However, now I am trying to clean up the layout and move parts of the code to a master page, I appear to be having problems...

My master page consists of a content placeholder in the head of the page (for any Javascript & CSS I want to include), and a "main" content placeholder containing the body of the file.

If I move the exact code into the separate content placeholders, the page doesn't function 100% correctly - I can move the portlets once and then I recieve a javascript error. I have narrowed the issue down to a line of code in the head of the page...

webpartString += $("#Panel2").sortable('toArray');


It appears that the CSS ID is not being found correctly when moving the code into the masterpage content placeholder.

I can get this code to work if I replace the CSS ID with the following:

webpartString += $('#<%= Panel2.ClientID %>').sortable('toArray');


But ideally I would like to stick to using the actual CSS ID ("Panel2") instead of the not very friendly looking "#ctl00_ContentPlaceHolderMain_Panel2".

Any idea how I can achieve this? (And why it is happening in the first place?).

Many thanks,

AJ