日期:2014-05-18  浏览次数:20742 次

应用模板页后如何调用js?
protected void Page_Load(object sender, EventArgs e)
  {
  Page.ClientScript.RegisterClientScriptInclude("key2", "~/js/testJs.js");
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "test1()");
  }
这是我应用模板页后的后台代码,我想调用testJs.js里的test1()函数,但是它就把我调用的函数写出来。
这是怎么回事。请大家帮帮忙吧。。非常感谢

------解决方案--------------------
帮你顶一下....

  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/
------解决方案--------------------
写出来的是什么样子,如果在<script>标记里,语法又正确的话,一定会执行的
------解决方案--------------------
顶一下,好久没写过代码了
------解决方案--------------------
ClientScriptManager.RegisterClientScriptInclude (Type, String, String) 

访问不了控件?不可能吧?你的TextBox1.Attributes["onfocus"]这些代码不是在模板页中吧(当然不能在那)
------解决方案--------------------
Page.ClientScript.RegisterClientScriptInclude("key2", "~/js/testJs.js"); 
把这个写在前台试试
<script type="text/javascript" src="~/js/testJs.js"></script>
------解决方案--------------------
学习了,帮顶
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e) 

Page.ClientScript.RegisterClientScriptInclude("key2", "~/js/testJs.js"); 

protected void Button1_Click(object sender, EventArgs e) 

Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "test1()",true); 


你少写个TRUE,最后这个TRUE就是为了添加javascript标记的
------解决方案--------------------

protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude("key2", "~/js/testJs.js");
this.callTest1=";
}
protected void Button1_Click(object sender, EventArgs e)
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "test1()");
this.callTest1 = "test1();";


.aspx文件中
onload="<%=callTest1%>"
------解决方案--------------------
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "test1()", true); 
或者
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script type='text/javascript'>test1()</script>"); 
再看下


------解决方案--------------------
探讨
ojlovecd 方法可以。那为什么要这样用啊?
这个textbox 的clientid=ctl00_MainContent_TextBox1;
为什么会变了呢?应该在什么情况下是用clientid,什么情况下用UniqueID,什么情况下直接用id呢?
难道在用户控件就用UniqueID,模板页就用clientid,平时就可以用id?
虽然我知道js是应用在客户端,也知道js所处理的全是html控件。