ScriptManager and UpdatePanel not found in namespace System.Web.UI

蹲街弑〆低调 提交于 2020-01-23 05:34:30

问题


I have a MVC4/Web API project and I created a test page that consumes the Web API using Ajax. Testing was going great, so I began working on the UI. One thing I needed to do was to populate some form controls with data returned from the Web API. I used JQuery for this.

Now, when I run the application and submit the form, I get an error indicating that the page had been updated:

Invalid postback or callback argument.  Event validation is enabled using <pages
enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %>
in a page.  For security purposes, this feature verifies that arguments to postback 
or callback events originate from the server control that originally rendered them.  
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation
method in order to register the postback or callback data for validation.

To overcome this problem I wrapped my form controls in an UpdatePanel and added the ScriptManager control. Now I get the following errors when building:

The type or namespace name 'ScriptManager' does not exist in the namespace 
'System.Web.UI' (are you missing an assembly reference?) C:\Users\xxx\Documents\
Visual Studio 2012\Projects\xxxxxxxxx\xxxxxxxx.Web.API\Public\
xxxxxxxxxxx.aspx.designer.cs    31  41  xxxxxxxx.Web.API

and

The type or namespace name 'UpdatePanel' does not exist in the namespace 
'System.Web.UI' (are you missing an assembly reference?)    C:\Users\xxx\Documents\
Visual Studio 2012\Projects\xxxxxxxx\xxxxxxxx.Web.API\Public\
xxxxxxxxxxx.aspx.designer.cs    40  41  xxxxxxxx.Web.API

I've completely cleaned my solution. Deleted obj/Debug and obj/Release. I've researched these 2 issues and they seem to go hand-in-hand as problems that crop up a lot. I've installed the AjaxControlToolbox, but that didn't make a difference.

Is there something I have to manually add to web.config or that I should be looking for?


回答1:


Add a reference to the assembly System.Web.Extensions. Select Project-> Add Reference and then select the assembly name.




回答2:


I understand why Garrison pointed out the MVC/Web Forms difference. I have some .aspx pages on my MVC site that I'm using for testing only.

But my problem was resolved by setting the target Framework of my project to 3.5 and then changing it back to 4.0 again.




回答3:


For me this issue comes when I copy/paste the ScriptManager and UpdatePanel blocks. The Systems.Web.Extensions reference was not pre-included in the project template, and a mere copy/paste did not add reference automatically. Adding the reference removed the error.

I am using .Net 3.5. I do not have any other framework installed so this kind of solved my problem.




回答4:


Simply add the row

<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web"%>

in the .aspx file and rebuild!




回答5:


For me the problem was that the designer had generated a row that said System.Web.UI.WebControls.ScriptManager rather than System.Web.UI.ScriptManager, which I think was because I gave it an id attribute when it doesn't need one.



来源:https://stackoverflow.com/questions/19122286/scriptmanager-and-updatepanel-not-found-in-namespace-system-web-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!