// ===================== protected void Page_Load(object sender,EventArgs e) { if(!IsP ostback) { //不起作用 Label1.Attributes.Add(" onclick"," ReportOnClick(''Label1)是 点击。'');"); //不起作用 // Label1.Attributes。添加(" onclick", " javascript :ReportOnClick(''Label1被点击。'');"); //工作 // Label1.Attributes.Add(" onclick"," alert(''Label1被点击。'');"); } } 因此,添加属性工作正常,因为如果我硬编码,我会收到警报 one in。但是,每当我尝试访问外部脚本中的函数时,我都会得到一个Microsoft JScript运行时错误:预期的对象。 有什么想法吗? 谢谢, PAGates 解决方案 " pagates" < pa ***** @ discuss.microsoft.com写信息 新闻:9A *********************** *********** @ microsof t.com ... 有什么想法吗? 最近在另一个帖子中讨论过类似的问题... 你如何将JavaScript文件包含在MasterPage ...? " Mark Rae"写道: 你如何在MasterPage中包含JavaScript文件......? // ===================== // MasterPage .master.cs // ===================== protected void Page_Load(object sender, EventArgs e) { ClientScript.RegisterClientScriptInclude(" MyJavaSc riptFile", " MyScriptFile.js"); } " pagates" < pa ***** @ discuss.microsoft.com写信息 新闻:D2 *********************** *********** @ microsof t.com ... " Mark Rae"写道: >你如何在MasterPage中包含JavaScript文件......? // ===================== // MasterPage .master.cs // ===================== protected void Page_Load(object sender, EventArgs e) { ClientScript.RegisterClientScriptInclude(" MyJavaSc riptFile", " MyScriptFile.js"); } 嗯 - 是的,我想我看到了问题... 你能不能做页面上的查看源并显示上面代码生成的 标记,即< include ...标题中的一行...... Hello All--I''m having a problem getting an onclick event to work. Here is my setup: Ihave an external JavaScript file, a master page that registers the javascriptas an external file, and a content page that has controls that I am trying toget onclick to work for.// =====================// MyScriptFile.js// =====================function ReportOnClick(msg){alert(''ReportOnClick: '' + msg);}// =====================// MasterPage.master.cs// =====================protected void Page_Load(object sender, EventArgs e){ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile","MyScriptFile.js");}// =====================// ContentPage.aspx.cs// =====================protected void Page_Load(object sender, EventArgs e){if (! IsPostback){// Does not workLabel1.Attributes.Add("onclick", "ReportOnClick(''Label1 wasclicked.'');");// Does not work// Label1.Attributes.Add("onclick","javascript:ReportOnClick(''Label1 was clicked.'');");// Does work// Label1.Attributes.Add("onclick", "alert(''Label1 was clicked.'');");}}So, the adding of the attribute works fine, as I get an alert if I hardcodeone in. However, whenever I try to access a function in my external script,I get a "Microsoft JScript runtime error: Object expected".Any ideas?Thanks,PAGates 解决方案 "pagates" <pa*****@discussions.microsoft.comwrote in messagenews:9A**********************************@microsof t.com...Any ideas?There was a similar problem discussed in another thread recently...How are you including the JavaScript file in the MasterPage...?"Mark Rae" wrote:How are you including the JavaScript file in the MasterPage...?// =====================// MasterPage.master.cs// =====================protected void Page_Load(object sender, EventArgs e){ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile","MyScriptFile.js");} "pagates" <pa*****@discussions.microsoft.comwrote in messagenews:D2**********************************@microsof t.com..."Mark Rae" wrote:>How are you including the JavaScript file in the MasterPage...?// =====================// MasterPage.master.cs// =====================protected void Page_Load(object sender, EventArgs e){ ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile","MyScriptFile.js");}Hmm - yes, I think I see the problem...Can you please do a View Source on the page and show the markup which theabove code has generated i.e. the "<include..." line in the header... 这篇关于onclick客户端代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 13:44