web控件代码:using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;
using System.IO;
using System.Data;
using System.Globalization;
using System.Collections;
using System.Drawing.Design;
using System.Security.Permissions;
using System.Web.UI.HtmlControls;[assembly: WebResource("WebCtrl.js.Demo.js", @"text/javascript")]
namespace WebCtrl
{
[PersistChildren(true), ParseChildren(false), ToolboxData("<{0}:FristCtrl runat=server></{0}:FristCtrl>")]
public class FristCtrl:WebControl
{
protected override void OnPreRender(EventArgs e)
{
//注册JS文件
Page.ClientScript.RegisterClientScriptResource(this.GetType(), "WebCtrl.js.Demo.js");
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(@"<div onclick='AlterTime();'>AlterTime</div>");
}
}
}
js文件路径 ~/js/Demo.js
js代码:function AlterTime()
{
alert(new Date());
}
添加一个web应用程序,在aspx文件里引用此控件.
找到不到函数.也就是说引用js不成功.怎么回事?
指点一下吧.谢谢.
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;
using System.IO;
using System.Data;
using System.Globalization;
using System.Collections;
using System.Drawing.Design;
using System.Security.Permissions;
using System.Web.UI.HtmlControls;[assembly: WebResource("WebCtrl.js.Demo.js", @"text/javascript")]
namespace WebCtrl
{
[PersistChildren(true), ParseChildren(false), ToolboxData("<{0}:FristCtrl runat=server></{0}:FristCtrl>")]
public class FristCtrl:WebControl
{
protected override void OnPreRender(EventArgs e)
{
//注册JS文件
Page.ClientScript.RegisterClientScriptResource(this.GetType(), "WebCtrl.js.Demo.js");
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(@"<div onclick='AlterTime();'>AlterTime</div>");
}
}
}
js文件路径 ~/js/Demo.js
js代码:function AlterTime()
{
alert(new Date());
}
添加一个web应用程序,在aspx文件里引用此控件.
找到不到函数.也就是说引用js不成功.怎么回事?
指点一下吧.谢谢.
[assembly: WebResource("WebCtrl.js.Demo.js", @"text/javascript",PerformSubstitution=true)]这样吗?好像还不行.
这么晚还没休息啊.