C# ASP.NET-在类库参考中使用ScriptManager

C# ASP.NET-在类库参考中使用ScriptManager,c#,asp.net,C#,Asp.net,我想在我的类库项目中添加对ScriptManager的引用,而不是ClientScriptManager,可能吗?我假设您不知道如何在通常不引用这些网络控件的类库中引用ScriptManager。此外,我认为您还需要知道如何在静态上下文中从类库获取对页面的引用 要获取ScriptManager,必须在类库项目中添加对System.Web.Extensions的引用 要在静态上下文中获取对页面的引用,您需要添加System.Web命名空间,然后下面返回当前页面的ScriptManager: C#:

我想在我的类库项目中添加对ScriptManager的引用,而不是ClientScriptManager,可能吗?

我假设您不知道如何在通常不引用这些
网络控件的类库中引用
ScriptManager
。此外,我认为您还需要知道如何在静态上下文中从类库获取对页面的引用

要获取
ScriptManager
,必须在类库项目中添加对
System.Web.Extensions
的引用

要在静态上下文中获取对页面的引用,您需要添加
System.Web
命名空间,然后下面返回当前页面的
ScriptManager

C#:

VB.NET:

Dim http = Web.HttpContext.Current
If Not http Is Nothing Then
    Dim page = TryCast(http.CurrentHandler, Web.UI.Page)
    If Not page Is Nothing Then
         Dim scriptManager = System.Web.UI.ScriptManager.GetCurrent(page)
    End If
End If

你能重新措辞这个问题吗?我不明白问题是什么。ScriptManager通常是一个ASP.NET标记,不确定如何将其添加到类库中。好的!谢谢但是我有一个问题,我不能以这种方式访问方法RegisterClientScriptBlock。你知道为什么吗?RegisterClientScriptBlock方法是静态/共享的。因此,这将起作用:
System.Web.UI.ScriptManager.RegisterClientScriptBlock(page,page.GetType,“ScriptKey”,“YourScript”,True)
Dim http = Web.HttpContext.Current
If Not http Is Nothing Then
    Dim page = TryCast(http.CurrentHandler, Web.UI.Page)
    If Not page Is Nothing Then
         Dim scriptManager = System.Web.UI.ScriptManager.GetCurrent(page)
    End If
End If