【问题标题】:The name 'ScriptManager' does not exist in the current context when calling JS function in Codebehind在 Codebehind 中调用 JS 函数时,当前上下文中不存在名称“ScriptManager”
【发布时间】:2014-09-23 05:14:08
【问题描述】:

当网站上没有回发时,我需要通过代码隐藏调用 JS 函数。 我已经在结束<head>标签之前添加了我的脚本:

<script type="text/javascript">
    function StartWidgetTour() {
        //init the tour!
        wWidgetTour.init();

        //finally start the tour! strange but we have to restart.
        wWidgetTour.restart();
    }
</script>

我的代码如下:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "Widget Tour Start!", "StartWidgetTour()", true);
        //more code that already works

当我想运行这段代码时,我收到了一个构建错误The name 'ScriptManager' does not exist in the current context

我已经在使用命名空间System.WebSystem.Web.UI;。 答案to this question 对我不起作用。

感谢您的帮助!

【问题讨论】:

    标签: c# javascript asp.net namespaces


    【解决方案1】:

    将脚本管理器添加到 *.aspx 页面

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
    </asp:ScriptManager>
    

    【讨论】:

      猜你喜欢
      • 2014-01-23
      • 2013-10-02
      • 2014-04-22
      • 2017-06-17
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      相关资源
      最近更新 更多