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 in开发者_如何学运维stance to add the stuff into without having to add a Page parameter. Somehow they're doing it... how can I?
You get the page reference through (Page)(HttpContext.Current.Handler)
even in a static context.
精彩评论