ASP.NET - Using ScriptManager in a link to a class library

I want to add a reference to the ScriptManager in my class library project, not the ClientScriptManager, is this possible?

+6
source share
1 answer

I assume that you do not know how to reference the ScriptManager in a class library, where these WebControls not usually referenced. In addition, I think you also need to know how to get the link to the page in a static context from the class library.

To get the ScriptManager , you must add a link to System.Web.Extensions to the class library project.

To get a link to a page in a static context, you need to add the System.Web , and then returns the ScriptManager current page:

FROM#:

 var http = System.Web.HttpContext.Current; if ((http != null)) { var page = http.CurrentHandler as Web.UI.Page; if (page != null) { var scriptManager = System.Web.UI.ScriptManager.GetCurrent(page); } } 

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 
+9
source

Source: https://habr.com/ru/post/894584/


All Articles