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>
<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>