Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScriptManager, Page, static methods... how do I get the current ScriptManager without Page?

I'm trying to extend ScriptManager to simplify dealing with resources that have multiple resource files (e.g. more than one script file as well as css). The goal is that I will be able to add a single ScriptReference to Scripts and have it load more than one resource related to that reference name.

What I'm getting stuck on is, how does your basic ScriptManager know what to do with stuff when when using static methods that do not include a Page parameter? For example:

ScriptManager.ScriptResourceMapping.AddDefinition("someName", new
   ScriptResourceDefinition { Path="/script/somescript.js"});

This adds a definition to (I guess) whatever the active script manager is for the page that's running when you call it. But unlike the old-school methods, like RegisterClientScriptBlock there is no parameter passed that identifies the page. But this stuff must get stored in the ScriptManager object, no? So how does it know?

I could always get a reference to the active one with this:

ScriptManager.GetCurrent(page);

but ideally, I would create new methods that work exactly like Microsoft's. I can't figure out how I could implement something like

ScriptManager.ScriptResourceMapping.AddDefinition(string name,
    ScriptResourceDefinition definition,
    ResourceType type)

that could figure out the object instance to add the stuff into without having to add a Page parameter. Somehow they're doing it... how can I?

like image 577
Jamie Treworgy Avatar asked Aug 29 '26 18:08

Jamie Treworgy


1 Answers

You get the page reference through (Page)(HttpContext.Current.Handler) even in a static context.

like image 63
Tim Schmelter Avatar answered Aug 31 '26 08:08

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!