
上QQ阅读APP看书,第一时间看更新
3.6.4 使用嵌入的资源
在没有RegisterClientScriptResource之前,我们通常都要自己从程序集中获取资源,再嵌入到网页中:
System.Type type = typeof(DiskFileUpload.FileItem); System.IO.Stream stream = type.Assembly.GetManifestResourceStream("DiskFileUploa d.client.js"); using (System.IO.TextReader reader = new System.IO.StreamReader(stream)) { string script = reader.ReadToEnd(); this.ClientScript.RegisterClientScriptBlock( this.GetType(), "script", script ); }
RegisterClientScriptResource也是ClientScriptManager中的一个方法,用于在网页中嵌入资源,通过RegisterClientScriptResource,我们可以简单地如下完成:
this.ClientScript.RegisterClientScriptResource( type, "DiskFileUpload.client.js");
type为嵌入资源的程序集中定义的某个类型,第二个参数就是资源的名称。