Element "X" is not a known element - web application

I have turned the forms website into an application and everything has been working fine so far. I keep getting green curved lines and the error that the β€œX” element is not a known element. This is on almost every element: Gridview, Label, update panel, hyperlink field, linked field, etc.

my web.config contains

<pages theme="basic"> <controls> <add tagPrefix="ajax" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </controls> </pages> 

therefore ajax and asp are viable prefixes. It is very strange that this happens only on a few user controls, all other user elements are in order and errors never appear. I tried to restart, and everything and nothing seemed to fix it. All master pages, web pages and about 90% of user controls are fine, only a few user controls are super annoying!

+4
source share
4 answers

If the compilation element in your web.config file has the targetFramework="4.0" attribute, I don’t think that references to the System.Web.Extensions assembly are more needed. If you look at the root level web.config file in %WINDIR%\Microsoft.NET\Framework\v4.0.30319\Config , you will notice that the following lines are already in the <controls> section of the web.config file:

 <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls.Expressions" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 

The System.Web.Extensions assembly also mentions the <compilation><assemblies> section

 <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 

and the following <httpHandlers> are added

 <add verb="*" path="*_AppService.axd" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False" /> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False"/> <add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False" /> 

In addition, by default, <httpModules> registered

 <add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 

In short, your web.config file should probably not contain references to the System.Web.Extensions assembly, as it is already mentioned in almost every possible way in the root level web.config file.

Additional links: How to upgrade an ASP.NET web application to ASP.NET 4

+6
source

I think this is a bug in Visual Studio. When I come across this, I will try to select everything on the aspx page, cut it, and then paste it right where it was. Then the controls should be added to the constructor file. If this does not work, delete the constructor file and try converting it to a web application again. Good luck I would also like to know if there is a better solution.

+1
source

I came across the same error, and first of all it turned out to be a problem considering the code with the CodeBehind attribute in the control declaration.

Next, the problem was asked.

 <%@ Control Language="C#" AutoEventWireup="true" Inherits="ContactListControl" Codebehind="ContactListControl.ascx.cs" %> 

Basically this change is to solve the problem

 <%@ Control Language="C#" AutoEventWireup="true" Inherits="ContactListControl" Codebehind="ContactListControl.ascx.cs" %> 

I suggest using the Visual Studio auto-formatting function (shortcut ctrl + k + d), it takes care of such heading / formatting issues.

+1
source

I had the same problem and tried everything until I deleted my suo file, then the problem disappeared

-3
source

All Articles