日期:2014-05-17  浏览次数:20439 次

JS 调用后台方法的问题。。
我想用JS来调用后台的sendmes_Onclik()方法,当用户点击私信后调用sendmes_Onclik()这个方法,可是我明明在JS里面写明了只有点击了按钮才会调用这个方法,可是实际上每当我进入这个页面的时候他就直接执行这个sendmes_Onclik()方法了,很郁闷啊,要怎么改啊?


HTML code
<a href="#" id="idBoxOpen" style="text-decoration: none; color: #00CCFF">私信</a></div>
   <dl id="idBox" class="lightbox" style="top: 10%; left: 5%;">
       <dd>
       asp:Label ID="Label8" runat="server" Text="内容:"></asp:Label>
       <asp:TextBox ID="TextBox2" runat="server" Height="80px" TextMode="MultiLine" Width="250px"></asp:TextBox>
       <br />
        <asp:Button ID="sendmes" runat="server" Text="私信" />
        </dd>
        </dl>



JScript code

<script type="text/javascript">
    (function () {

        var ab = new AlertBox("idBox"), lock = false;

        $$("sendmes").onclick = function () {
            
            
                "<%=sendmes_Onclik() %>";
                
                ab.close();
            }

        
        $$("idBoxOpen").onclick = function () {

            ab.center = true;
            ab.show();
        }
    })()

</script>




------解决方案--------------------
Jquery不是这样玩的
JScript code

  $ (function () {
        var ab = new AlertBox("idBox");
       lock = false;
        $("sendmes").click = function () {          
              //你的点击操作
            }
      });

------解决方案--------------------
button的事件放在button上,
<asp:Button ID="sendmes" runat="server" Text="私信" onclick="sendmes_Onclik" style="height: 21px" />
点击私信后就执行sendmes_Onclik中的内容了,不需js,还是按通常的思路比较好。
如果用到在执行sendmes_Onclik的过程中用到js,用asp.net中的js注册方法实现。
------解决方案--------------------
楼主是想用js调用后台方法吧

很简单你百度搜一下 __doPostBack吧,
然后你就明白了。
------解决方案--------------------
JScript code

    $$("sendmes").onclick = function () {
        <%=Page.ClientScript.GetPostBackEventReference(this.Page, "")%>;
        ab.close();
    }