如何在 class 中引用 UI.Page

How to reference UI.Page in a class

我有一个助手 class,我想 运行 使用 ScriptManager 的客户端脚本:

public static void HideMessage()
{
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "hideMessage", "hideMessage();", true);
}

除了我无法引用页面,因为我收到错误,"Class name is not valid at this point"。我意识到我可以将页面从后面的 webform 代码传递到方法中。有没有不使用参数引用页面的方法?

HttpContext.Current.CurrentHandler代替Page怎么样:

 ScriptManager.RegisterStartupScript(
    HttpContext.Current.CurrentHandler, 
    HttpContext.Current.CurrentHandler.GetType(), 
    "hideMessage", 
    "hideMessage();", 
    true);