pingoo
pingoo

Reputation: 2064

ASP.Net 3.5 Client ID's different to 4.0

We're attempting to upgrade our site from framework 3.5 to 4.0. Everything appears to be fine server side - My only problem so far is the IDs of a handful of custom controls.

The Controls deceleration looks like:

    <div runat="server" id="gglSelectedItemsImage" class="gplSelectedItemsText">None selected</div>

When rendered in 3.5 the control looks like:

<div id="gplCategories_gglSelectedItemsImage" class="gplSelectedItemsText">Some Content</div>

And in 4.0 Like:

<div id="ctl00_ctl00_ctl00_ContentPlaceHolder1_Content_gplCategories_gglSelectedItemsImage" class="gplSelectedItemsText">Some Content</div>

This is causing some of our older JavaScript/JQuery to fail.

I've set <pages clientIDMode="AutoID" controlRenderingCompatibilityVersion="3.5" /> in the web.config so 99.9% of the IDs are correct. The weirdest thing is the 3.5 control looks like it rendering with clientIDMode="Predictable" rather than the standard 3.5 auto IDs?

Furthermore if I access the controls clientID Server side in 4.0 it appears correct:

Me.gglSelectedItemsImage.ClientID = "gplCategories_gglSelectedItemsImage"

This is the main problem, any values inserted into the JavaScript ect are actually the wrong values.

Our site is unfortunately to large to just fix this one error so I need to work out why the control is rendering its ID differently and implement it across the site.

Any idea's you guys have will be very much appreciated.

Upvotes: 1

Views: 3340

Answers (3)

James Johnson
James Johnson

Reputation: 46057

In the second example you're using a master page, which explains why the ClientID is different. It shouldn't make a difference though if you're referencing the control by ClientID:

var ctrl = $("#<%=gglSelectedItemsImage.ClientID%>");

Upvotes: 1

Fahad
Fahad

Reputation: 1271

Try this

<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>

Upvotes: 1

Graymatter
Graymatter

Reputation: 6587

You should access the client id's like this in your .ASPX file:

<%=gglSelectedItemsImage.ClientID%>

Upvotes: 0

Related Questions