开发者

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

开发者 https://www.devze.com 2023-01-19 23:39 出处:网络
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_drpB开发者_C百科anks\" where it was

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_drpB开发者_C百科anks" 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消