0

Error message:

Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Other solutions tell one to modify the markup syntax in various ways, but I've been ordered to keep the markup as-is if possible. We need to still compile this stuff on older systems.

Is there a way to turn off this "controls collection" feature to avoid a conflict, since I don't need it?

I opened project as a "Web Site" project, as I don't need most the Web Forms features. The percent syntax used to be ubiquitous, surely there's a work-around somewhere.

11
  • 2
    I'm using VS2022 with an old-school .NET 4.0 WebForms .aspx/.ascx project just fine. I think the problem is you're using a "Web Site" project: you need to convert it to a "real" Web Application project first. Commented Oct 30 at 23:08
  • 1
    Well, are you sure this was a "web site"? If it was built as a asp.net web site applicaiton? Then you MUST open the .sln project, and you can NOT use file->open web site. And in fact, the reverse is also true! -- if that was a "web site", then you can NOT use and open the project as .sln, but MUST continue to use file->open web site. So, it not a question of what you prefer here, but that you MUST contine working on that project as it was designed. The page directive (and referencing) will change if you open the project the wrong way. Commented Oct 30 at 23:11
  • This likely explains the issue(s) you are having here. You can NOT mid way through development change your mind, and attempt to open a "application" as web site - as noted, referencing, and even the @page directive used are different in both project types and choices. I hands down prefer the application, but some don't, since even one tiny change to a page code requires a full re-build and full re-deploy. However, that' a small price to pay for the many extra features you gain (such as allowing multiple projects in one, and better compile time resolution of errors, and better class support). Commented Oct 30 at 23:13
  • 1
    Not sure why this question was closed? This has NOTHING to do with converting a web site to a web application - ZERO - the user wants to keep things "as is". And those % server side expressions should continue to work in VS2022 - that behavior has not been changed.... Commented Oct 31 at 23:19
  • @AlbertD.Kallal Adding a .csproj file won’t involve making any changes to .aspx markup/render-syntax. Commented Nov 17 at 3:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.