protected void Page_Load(object sender, EventArgs e)
    {
           this.Button1.Attributes.Add("onclick", "myfn()");
       
    }
       public void fnTest()
    {
        this.TextBox1.Text = "----------";
       
    }怎么将这个"myfn()"js方法,换成后台方法"fnTest()"

解决方案 »

  1.   

    onclick本来就是前台的脚本事件。。
      

  2.   


    这个我知道啊!我的意思是说,
    onclick执行的js事件,可不可改为后台方法
      

  3.   

    this.Button1.Click += new EventHandler(fnTest)
           public void fnTest()
        {
            this.TextBox1.Text = "----------";
           
        }
    这个方法要改成
           public void fnTest(object sender, EventArgs e)
        {
            this.TextBox1.Text = "----------";
           
        }这样传递的委托才能创建
      

  4.   

    LS的误会我的意思了!(这个服务器后台方法fnTest(),我可以直接写在Button1的后台onclick事件里)我的意思是,this.Button1.Attributes.Add("onclick", "myfn()");这里添加的js方法,可不可以改为服务器后台方法fnTest()
    虽然说意义不大,主要是问可不可以实现!
      

  5.   


    执行服务器方法 ? ajax?
      

  6.   

    this.Button1.Attributes.Add("onclick", "myfn()");
    这句话只是给button添加一个属性 。
    要访问后台方法 必须ajax 。
      

  7.   

    可是可以,不过要通过ajax,而且参数传递和结果回传都要你处理
      

  8.   

    js 是在客户端执行!
    要调用服务器方法,可以用 ajax