JavaScript$$c#

来源:互联网 发布:c语言链表 编辑:程序博客网 时间:2024/05/14 08:45

C#中如何调用Javascript函数?

在.cs页面中使用javascript函数,例子  
  string   indexpage="XXX.aspx";  
  Response.Write("<script>");  
  Response.Write("parent.frames[1].location.href='indexpage'");        
  Response.Write("</script>");  
 

服务器端调用脚本函数  
  写一个javascript  
  function   test()  
  {  
    alert("ok");  
  }  
   
  如果控件是runat=server的话,那么就在那个Button1.attribute["onkeypress"]="javascript:test()";  
  html控件:  
  <intput   type=textbox   onkeypress="test()">就行了


Response.Write("<script   language=javascript>function1()</script>")

aspx里的代码:  
  function   test(){  
  }  
   
  在aspx.cs的page_load写下代码:  
  Button1.attribute["click"]="javascript:test()";  
   
  或者  
  Button1.attribute.Add("click","test()");  
   

Page.RegisterStartupScript("("<script   language=javascript>function1()</script>");  
  楼上的方法也可行。 

 
原创粉丝点击