| new object[2] { resourceName, control.GetType().Assembly }) as string;
//}
//else
return this.clientScript.GetWebResourceUrl(type, resourceName);
}
}
The code basically checks to see whether the MS Ajax assembly can be accessed as a type and if so assumes MS Ajax is installed. This is not quite optimal – it’d be better to know whether a ScriptManager is actually being used on the current page, but without scanning through all controls (slow) I can’t see a way of doing that easily.
The control caches each of the MethodInfo structures to defer some of the overhead in making the Reflection calls to the ScriptManager methods. I don’t think that Reflection here is going to cause much worry about overhead unless you have a LOT of calls to these methods (I suppose it’s possible if you have lots of resources – think of a control like FreeTextBox for example). Even then the Reflection overhead is probably not worth worrying about.
To use this class all calls to ClientScript get replaced with call this class instead. So somewhere during initialization of the control I add:
protected override void OnInit(EventArgs e)
{
this.ClientScriptProxy = ClientScriptProxy.Current;
base.OnInit(e);
}
And then to use it:
this.ClientScriptProxy.RegisterClientScriptInclude(this,this.GetType(),
&nbs 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |