1

I am in the process of upgrading a legacy ASP.Net Website (Web Forms) from .NET 3.5 to .NET 4.5. I recently noticed after the upgrade some ASP.Net controls were re-named from ctl00_Content_dropDown1 to ctl00$Content$dropDown1 in the HTML, breaking a lot of the client-side JavaScript.

How can I stop this change from occurring after the upgrade?

Kyle B
  • 2,328
  • 1
  • 23
  • 39

1 Answers1

1

docs.Microsoft.com says that moving from .NET 3.5 to .NET 4.0 (or greater) causes this breaking change that changes the way that the id attribute for elements is generated.

In the web.config file, change the <pages> element, add the clientIDMode attribute to it like this:

<pages clientIDMode="AutoID" ...

This should continue making IDs in the way that it did before.

In addition to AutoID, MSDN lists several other useful options:

  • AutoID - Auto-generate the segments with the underscore character
  • Inherit - Inherit the mode from the parent container
  • Predictable - Default value for a page in .NET 4.0 and up
  • Static - ClientID is set to the value of the ID property

Visual Studio is supposed to set the ClientIDMode to AutoID when you upgrade from .NET 3.5 to .NET 4.5, however I don't think it works when you do not have a ASP.Net Web Project (.csproj) and instead all you have is a ASP.NET Website.

Kyle B
  • 2,328
  • 1
  • 23
  • 39