0

我正在尝试从 asp.net 应用程序中的 C# 类执行 javascript 函数。我正在使用ScriptManager. 我有一个类UpdateUI,其中包含以下方法:

public static void RunScript()
{
    try
    {
        if (HttpContext.Current != null)
        {
            Page currentPage = HttpContext.Current.Handler as System.Web.UI.Page;
            ScriptManager.RegisterClientScriptBlock(currentPage, currentPage.GetType(), "disableControls", "disableControls()", true);
        }
    }
    catch (Exception ex)
    {
    }
}

当我UpdateUI.RunScript()从另一个静态类调用时,HttpContent.Currentnull. 知道我应该如何去才能从非代码隐藏的类中执行脚本管理器吗?

4

1 回答 1

0

Pass the HttpContext to the method within your static class. As Tim Schmelter's comment indicates, calling HttpContext.Current will fail if it's not done in response to an incoming request.

public static void RunScript(HttpContext context);
于 2013-05-08T14:48:50.303 回答