asp.net Ajax Primer Series (3): Using the ScriptManagerProxy control

Source: Internet
Author: User

In ASP.net Ajax, because there is only one ScriptManager control on an ASPX page, in the case of a master page, if you need to introduce different scripts in Master-page and Content-page, This requires the use of scriptmanagerproxy in Content-page, rather than Scriptmanager,scriptmanager and ScriptManagerProxy are two very similar controls.

A ScriptManagerProxy Control Overview

In ASP.net Ajax, because there is only one ScriptManager control on an ASPX page, in the case of master-page, if you need to introduce different scripts in Master-page and Content-page, You need to use ScriptManagerProxy in Content-page instead of Scriptmanager,scriptmanagerproxy and ScriptManager are two very similar controls. The simple definition form is as follows:

<asp:ScriptManagerProxyid="ScriptManagerProxy1"runat="server">
  <Services>
        <asp:ServiceReferencePath="CalculWebService.asmx"/>
  </Services></asp:ScriptManagerProxy>

The sub tags that can be added below it are: Services,scripts,authenticationservice,profileservice

Two Simple example

Let's look at a simple example of using ScriptManagerProxy.

1. First we prepare two webservice, we enter a string in the Master-page, and in Content-page we ask for two numbers.

Simplewebservice.asmx

[ScriptService]
  public class SimpleWebService : System.Web.Services.WebService {
  public SimpleWebService () {
  //Uncomment the following line if using designed components
  //InitializeComponent();
  }
  [WebMethod]
  public string EchoString(String s)
  {
    return "Hello " + s;
  }
  }
  CalculWebService.asmx  [ScriptService]
  public class CalculWebService : System.Web.Services.WebService {
  public CalculWebService () {
  //Uncomment the following line if using designed components
  //InitializeComponent();
  }  [WebMethod]
  public int Add(int a,int b) {
  return a + b;
  }
}

2. Add a master-page, add a ScriptManager control over it, introduce WebService simplewebservice.asmx, and add the corresponding HTML element:

<div>  <asp:ScriptManagerID="ScriptManager1"runat="server">    <Services>      <asp:ServiceReferencePath="SimpleWebService.asmx"/>    </Services>  </asp:ScriptManager>  <asp:contentplaceholderid="ContentPlaceHolder1"runat="server">  </asp:contentplaceholder>

  &nbsp;
  <inputid="button"type="button"value="确定"onclick="returnOnbuttonGo_click()"/>

</div>

Write the appropriate JS code:

<script type="text/javascript" language="JavaScript">
  function OnbuttonGo_click()
  {
    requestSimpleService = SimpleWebService.EchoString(
  document.getElementById('inputName').value,    //params
  OnRequestComplete  //Complete event
  );
  return false;
  }
  function OnRequestComplete(result)
  {
    alert(result);
  }
  </script>

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.