Sandhurst
Sandhurst

Reputation: 1180

ClientID getting changed when deploying asp.net 2.0 website to Framework 4.0

I have a website which is hosted on GoDaddy they have version 4.0 runtime. The issue is the client id of the server controls are generated as "contentPlaceHolder1_drpBanks" where it was earlier (when the website was on some other server) getting generated as "ctl00_contentPlaceHolder1_drpBanks".

What I need to know is there a way to resolve this so that I don't have to make any changes in the code.

Like a setting in web.config file or something.

Upvotes: 2

Views: 2131

Answers (2)

m.edmondson
m.edmondson

Reputation: 30892

In the future use <%=Control.ClientID%> which will successfully resolve every time - without code changes.

Upvotes: 2

Ronald Wildenberg
Ronald Wildenberg

Reputation: 32134

Controls in ASP.NET 4.0 have a ClientIDMode property. If you set this to AutoID, ASP.NET should generate client ids in the same way it did in ASP.NET 2.0. Here's an article that explains the different client id modes.

Besides setting ClientIDMode at the control level, you can also set it at the page or application level:

<%@ Page Language="C#" ClientIDMode ="AutoID" ... %>

or

<system.web>
    <pages clientIDMode="AutoID" />
</system.web>

But I agree with leppie's comment that it is dangerous to rely on generated client ids.

Upvotes: 1

Related Questions