. NET without Ajax to implement the front desk JS call the background C # method (Tips)

Source: Internet
Author: User

Pure skill, Master laughed at.

When it comes to how to call the backend C # method in the foreground JS, Ajax becomes an inevitable idea.

Just implement the details using AJAX 1.0 or Ajaxpro difference.

In fact, if not Ajax, we can easily use JS to invoke the backend method.

The steps are as follows:

1 Front desk put a button. Set to hidden. Note: You cannot set the Visible=false directly, so you cannot find this button in the ASP.net 2.0 compiled code. Need to set style: Style= "Display:none;"

2 Double-click the button, write to the C # method, or write a code snippet that calls other methods in the background

3 The front desk JS call, as follows, so you can simulate the click of the button event, triggering the background method:

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

Example

Asp. NET page:

<script>
  function go()
  {
    document.getElementById("Button2").click();
  }
  </script>

<body>
  <form id="form1" runat="server">
    <div>
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="go();return false;" />
      <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" Style="display: none;" />
    </div>
  </form>
</body>

Related Article

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.