C # and JavaScript call each other

Source: Internet
Author: User

1. C # calls JavaScript (1) to prepare JavaScript functions <script type= "Text/javascript" > Function say () { Alert ("CSharp call JS, the call succeeds!")                "); } </script> (2) page code <asp:button id= "Button1" runat= "Server" text= "CSharp call js" onclick= "Button1_Click"/> (3 ) C # code protected void Button1_Click (object sender, EventArgs e) {Page.ClientScript.RegisterStartupScript (Clie Ntscript.gettype (), "Say", "<script>say ();    </script> "); }2, JavaScript calls C # code (1) page code <input type= "button" value= "JS call CSharp" onclick= "Jscallcsharp ();"/> <as P:button id= "Button2" runat= "Server" text= "I am the hidden button" onclick= "button2_click" style= "Display:none;" /> (2) C # code//Background method public void Show () {Response.Write ("JS Invoke background method succeeded!    ");    }//Hide button event protected void button2_click (object sender, EventArgs e) {Show (); } (3) JavaScript code <script type= "Text/javascript" > Function Jscallcsharp () {document.getElementById ("Button2"). Click (); } </script>

  

C # and JavaScript call each other

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.