C#调用js,js调用C#

作者:互联网   出处:控件中国网   2014-11-05 19:05:42   阅读:1

C#调用js,js调用C#

js:

       <script type="text/javascript">

        function ss() {

            alert("底层调用js,调用成功!");

        }

        //这个方法用了调用隐藏按钮

        function xx() {

            document.getElementById("Button2").click();

        }

      </script>

html:


   <asp:Button ID="Button1" runat="server" Text="底层调用js" onclick="Button1_Click" />


        <hr />


        <input type="button" value="js调用底层" onclick="xx();" />


        <asp:Button ID="Button2" runat="server" Text="我是隐藏按钮" onclick="Button2_Click" style="display:none;"/>


        <hr />


CS:

 

    //底层调用js


    protected void Button1_Click(object sender, EventArgs e)


    {


        Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "gg", "<script>ss(); </script>");


    }


   


    //后台方法


    public void showval()


    {


        Response.Write("js调用后台方法成功!");


    }

 


    //隐藏按钮事件


    protected void Button2_Click(object sender, EventArgs e)


    {


        showval();


    }

 

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat