I want to add a reference to ScriptManager in my class library project instead ClientScriptManager, is it possible?
I would put the ScriptManager at the top of the Master page outside of any Multi-View. The ScriptManager is a what is used by the Microsoft controls to provide AJAX functionality.
ScriptManager is a server-side control that sits on your Web Form and enables the core of ASP.NET AJAX. Its primary role is the arbitration of all other ASP.NET AJAX controls on the Web Form and the addition of the right scripting libraries to the Web browser so that the client portion of ASP.NET AJAX can function.
RegisterStartupScript(Control, Type, String, String, Boolean) Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.
ScriptManager control registers the script for the Microsoft AJAX Library with the page. This enables client script support features such as partial-page rendering and Web-service calls. You must use a ScriptManager control on a page to enable the following features of ASP.NET AJAX: 1.
I assume that you don't know how to reference the ScriptManager
in a class library where normally these WebControls
are not referenced. Furthermore i think you also need to know how to get a reference to the page in a static context from the class library.
To get the ScriptManager
you have to add a reference to System.Web.Extensions
in your class library project.
To get a reference to the page in a static context you need to add the System.Web
namespace, then following returns the ScriptManager
of the current page:
C#:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With