将js文件编译成动态链接库(dll)文件
作者:互联网
2009-06-09
1.向项目中添加Jscript文件
//script_1.js-----
function doClick1()
{
alert("OK1_wufeng");
}
//script_2.js-----
function doClick2()
{
alert("OK2");
}
2.解决方案资源管理器中,右键查看script_1.js和script_2.js的属性,把高级中的“生成操作”属性设置成“嵌入的资源”。
3.向AssemblyInfo.cs文件中添加如下行:(注意域名wf.ClientScriptResourceLabel)
[assembly: System.Web.UI.WebResource("wf.ClientScriptResourceLabel.script_1.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("wf.ClientScriptResourceLabel.script_2.js", "application/x-javascript")]
4.向项目中添加一个类, 实例:
using System;
using System.Drawing;
using System.Web.UI;
using System.Web;
using System.Globalization;
namespace wf.ClientScriptResourceLabel
{
public class ClientScriptResourceLabel : System.Web.UI.WebControls.WebControl
{
//调用脚本资源
protected override void OnPreRender(EventArgs e)
{
if (this.Page != null)
{
this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf.ClientScriptResourceLabel.script_1.js");
this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf.ClientScriptResourceLabel.script_2.js");
}
base.OnPreRender(e);
}
///
/// 呈现控件的方法RenderContents
///
protected override void RenderContents(HtmlTextWriter output)
{
output.AddAttribute("id", "1");
output.AddAttribute("type", "checkbox");
output.AddAttribute("value", "测试1");
output.AddAttribute("onclick", "javascript:doClick1();");
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
output.AddAttribute("id", "2");
output.AddAttribute("type", "checkbox");
output.AddAttribute("value", "测试2");
output.AddAttribute("onclick", "javascript:doClick2();");
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
base.RenderContents(output);
}
}
}
大家可以试试
相关标签:
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
目录:VTJ.PRO 在线应用开发平台技术揭秘
4.响应式系统基础:从发布订阅模式的角度理解 Vue3 的数据响应式原理
vue3中静态提升和patchflag实现
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
Vue3 转 React:组件透传 Attributes 与 useAttrs 使用详解|VuReact 实战
使用 VueUse 构建一个支持暂停/重置的 CountUp 组件
vue2中使用 AntV G6
前端视频媒体带声音自动播放方案最佳实践和教程
[前端]可折叠容器组件、信息展示卡片组件
AI精选
