|
源代码网推荐
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); 源代码网推荐 } 源代码网推荐 } 源代码网推荐}
源代码网推荐大家可以试试 <--正文内容结束-->
源代码网供稿. |