我现在有一个button如下:
 <input  type="button" id="b2" onclick="test();" value="b2" />
js脚本如下:
  function test() {
        <% test();%>
               }
后台的代码:public void test() 
        {
            string d;
            d = "dd";
        }
我的test方法只有在页面加载的时候触发,点击我的button时不触发,
请问怎么调用呢?

解决方案 »

  1.   

    js    要调用后台方法     使用Ajax吧
      

  2.   


    这是我用Jquery写的前台调用页面类方法的示例LZ看看。。
      

  3.   

    AjaxPro使用方法
      

  4.   

    onclick
    改为
    OnClientClick.
      

  5.   

    需要使用ajax调用的 在C#方法前部加入[webmethod] 使用ajax框架调用 推荐jquery
      

  6.   

    可以用HiddenField来获取后台的值,然后再js中处理
      

  7.   

    参考:
    http://www.cnblogs.com/insus/articles/2036271.html
    另外:
    http://www.cnblogs.com/insus/articles/1961627.html
      

  8.   

    请大侠用AjaxPro 给写个例子吧
      

  9.   

    AjaxPro 没用过
    使用微软的标准方法实现Ajax
    http://blog.csdn.net/xuexiaodong2009/archive/2011/06/09/6533466.aspx
      

  10.   

    问题解决了:参照下面的文档:
    http://hi.baidu.com/conggang/blog/item/a92fd0ae0289ebe3fbed50a9.html
    我的解决步骤:
    1. Page_Load方法中添加:
    AjaxPro.Utility.RegisterTypeForAjax(typeof(advertisement_add));
    advertisement_add 是我的class名字
    2. 方法改成
     [AjaxPro.AjaxMethod]
            public void test() 
            {
                string d;
                d = "dd";
            }
    3. js 直接<script type="text/javascript">
        function test() {
            Maunite.Web.Admin.adset.advertisement_add.test();         
        }
      
    </script>
    这样就搞定了!!
    谢谢大家了