helloajax.com
专注Ajax、Asp.Net、JavaScript技术
正在加载Ajax相关信息.................
(网赚 学发财) 用户名: 游客 ( 登录 | 注册 ) 新短信:0 条
首页   搜索    会员    控制面版    在线用户   简洁版本

网赚 学发财»Ajax通信层(A)»把js文件嵌入动态联接库dll中

回复:0,点击:1500
把js文件嵌入动态联接库dll中 Expand / Collapse 收藏本主题
作者
内容
qucha
发表时间 2007-4-7 12:08:29



等级: 列兵
贴子: 6
主题:6
最后登录: 2008-9-17 11:05:00
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);
        } 


        /// <summary> 
        /// 呈现控件的方法RenderContents
        /// </summary>
        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);
        }
    }
}


第 1 楼
OFFLINE
1 TotalRecords, 1/1 TotalPages 1

设置固顶 删除主题 锁定主题 移动贴子
强力推荐: 趣查网  ©2006 HelloAjax.Com
执行时间: 0.468786 second(s) 查询数据:8内存用量:6,681 KB