javascript 当前上下文中不存在名称“ScriptManager”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20941334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:39:57  来源:igfitidea点击:

The name 'ScriptManager' does not exist in the current context

javascriptasp.netwebformsasp.net-ajaxscriptmanager

提问by Dean

I copied some code to solve a problem with running JavaScript after an AJAX postback in ASP.Net. Unfortunately the new code gave me the following error when doing a build:

我复制了一些代码来解决在 ASP.Net 中的 AJAX 回发后运行 JavaScript 的问题。不幸的是,新代码在构建时给了我以下错误:

The name 'ScriptManager' does not exist in the current context

Now I've used the ScriptManager before, so why would it be giving me problems now? Isn't it available on all ASP.Net pages? I have a script manager on my master page after all...

现在我以前使用过 ScriptManager,为什么现在它会给我带来问题?它不是在所有 ASP.Net 页面上都可用吗?毕竟我的母版页上有一个脚本管理器......

回答by Dean

I suppose there could be a number of things wrong that would generate this error message. But for me, all I had to do was add the following using to the top of my code-behind file:

我想可能有很多错误会产生此错误消息。但对我来说,我所要做的就是将以下内容添加到我的代码隐藏文件的顶部:

using System.Web.UI;

I hope this helps someone out there, maybe it'll save you some time.

我希望这可以帮助那里的人,也许它可以为您节省一些时间。

回答by hims056

If you are not getting ScriptManagerin System.Web.UIthen add a reference for System.Web.Extensions. (Go to solutions explorer -> right click on project -> Select add reference -> in .Nettab select System.Web.Extensionsand click OK). This worked for me when I was getting that error even after using System.Web.UI.

如果您没有进入ScriptManager,请System.Web.UI添加对System.Web.Extensions. (转到解决方案资源管理器 -> 右键单击​​项目 -> 选择添加引用 -> 在.Net选项卡中选择System.Web.Extensions并单击OK)。即使在使用System.Web.UI.