在命名空间 System.Web.UI 中找不到 ScriptManager 和 UpdatePanel

问题描述 投票:0回答:6

我有一个 MVC4/Web API 项目,我创建了一个使用 Ajax 使用 Web API 的测试页面。测试进展顺利,所以我开始研究 UI。我需要做的一件事是使用从 Web API 返回的数据填充一些表单控件。我为此使用了 JQuery。

现在,当我运行应用程序并提交表单时,我收到一条错误消息,表明页面已更新:

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.

为了克服这个问题,我将表单控件包装在 UpdatePanel 中并添加了 ScriptManager 控件。现在我在构建时遇到以下错误:

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

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

我已经完全清理了我的解决方案。删除了 obj/Debug 和 obj/Release。我研究了这两个问题,它们似乎是齐头并进的问题,经常出现。我已经安装了 AjaxControlToolbox,但这没有什么区别。

有什么我必须手动添加到 web.config 或我应该寻找的东西吗?

asp.net asp.net-ajax ajaxcontroltoolkit scriptmanager
6个回答
34
投票

添加对程序集System.Web.Extensions的引用。选择 Project-> Add Reference,然后选择程序集名称。


6
投票

对我来说,问题是设计师生成了一行,上面写着

System.Web.UI.WebControls.ScriptManager
而不是
System.Web.UI.ScriptManager
,我认为这是因为我在它不需要的时候给了它一个
id
属性。


5
投票

我理解为什么 Garrison 指出 MVC/Web Forms 的区别。我的 MVC 网站上有一些 .aspx 页面,仅用于测试。

但是通过将项目的目标框架设置为3.5,然后再次将其改回4.0,我的问题得到了解决。


4
投票

对我来说,当我复制/粘贴

ScriptManager
UpdatePanel
块时,就会出现这个问题。
Systems.Web.Extensions
引用未预先包含在项目模板中,仅复制/粘贴不会自动添加引用。添加引用消除了错误。

我正在使用.Net 3.5。我没有安装任何其他框架,所以这解决了我的问题。


4
投票

只需添加行

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

在 .aspx 文件中并重建!


0
投票

我们收到“命名空间‘System.Web.UI’中不存在类型或命名空间名称‘ScriptManager’”错误。

但是对于我们来说,IDE 和构建输出不匹配:构建输出给出了错误,而 IDE 没有突出显示任何错误。我们尝试了清理、重建等,但没有任何效果。

所以,我们:

  • 关闭 Visual Studio。
  • 删除了
    .vs
    bin
    obj
    目录。
  • 重新启动 Visual Studio。

现在一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.