我在后台page_load中写了
this.b_check.Attributes.Add("onclick","check(file)");
其中b_check是一个asp:button,我想让他执行写在前台的javascript函数check(file)
<script  language=javascript  type=text/javascript>

function check(file){  
var  fs  =  new  ActiveXObject("Scripting.FileSystemObject") 
 var txt=document.getElementsById("txt");
if(fs.FileExists(file)) 
txt.value="true";  else 
txt.value="false";
 } 
</script>
但是没有执行阿!为什么呢?

解决方案 »

  1.   

    可以在前面button里面这样写啊
    OnClientClick="check(file)" CausesValidation="False" UseSubmitBehavior="False" Visible="False"
      

  2.   

    this.b_check.Attributes.Add("onclick","check(file)");
    file应该是具体的值吧。
      

  3.   

    file应该是个具体的值啊,如果是个变量,应该是this.b_check.Attributes.Add("onclick","check("+file+")");
      

  4.   

    就是在javascript里file是参数,
    但在cs里,file就要是具体值。
    this.b_check.Attributes.Add("onclick","check('"+file+"')");
      

  5.   

    应该就是check()里面传参数的问题,,
    按楼上说的试试吧,
      

  6.   

    谢谢各位的建议,可是我的这个javascript函数却没有调用成功?在后台该怎么调用呢?
      

  7.   

    this.b_check.Attributes.Add("onclick","check('C:\\txt.doc')");
      

  8.   

    换个问题问下:怎么在C#后台调用前台的javascript的函数呢?是带参数和返回值的!
      

  9.   

    this.b_check.Attributes.Add("onclick","check('C:\\txt.doc')");
    这个我测试了 但是没有反应  没有得到返回值
      

  10.   

    在函数开头加alert()
    看能否调用这个函数