In ASP. net Ajax, because An ASPX page can only have one scriptmanager control, in the case of a 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, scriptmanager and scriptmanagerproxy are two very similar controls.
Main Content
1. scriptmanagerproxy control Overview
2. Simple Example
1. Overview of the scriptmanagerproxy Control
In ASP. net Ajax, because An ASPX page can only have one scriptmanager control, 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 is as follows:
<Asp: scriptmanagerproxy id = "scriptmanagerproxy1" runat = "server">
<Services>
<Asp: servicereference Path = "calculwebservice. asmx"/>
</Services>
</ASP: scriptmanagerproxy>
The following sub-tags can be added: services, scripts, authenticationservice, profileservice
Ii. Simple Example
The following is a simple example of using scriptmanagerproxy.
1. First, we prepare two WebServices. In master-page, we enter a string, and in content-page, we calculate the sum of 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;
}
}
2. Add a master-page, add a scriptmanager control on it, introduce WebService simplewebservice. asmx, and add the corresponding HTML elements:
<Div>
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
<Services>
<Asp: servicereference Path = "simplewebservice. asmx"/>
</Services>
</ASP: scriptmanager>
<Asp: contentplaceholder id = "contentplaceholder1" runat = "server">
</ASP: contentplaceholder>
& Nbsp;
<Input id = "inputname" type = "text"/>
<Input id = "button" type = "button" value = "Confirm" onclick = "Return onbuttongo_click ()"/>
</Div>
3. Add a content-page, add a scriptmanagerproxy control on it, introduce WebService calculwebservice. asmx, and add the corresponding HTML elements:
<Div>
<Asp: scriptmanagerproxy id = "scriptmanagerproxy1" runat = "server">
<Services>
<Asp: servicereference Path = "calculwebservice. asmx"/>
</Services>
</ASP: scriptmanagerproxy>
<H3> enter two numbers:
<Input id = "inputb" style = "width: 110px" type = "text"/> & nbsp;
<Input id = "buttonequal" type = "button" value = "=" onclick = "Return onbuttonequal_click ()"/>
</Div>
Compile the corresponding JS Code:
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function onbuttonequal_click ()
{
Requestsimpleservice = calculwebservice. Add (
Document. getelementbyid ('inputa'). Value, // Params
Document. getelementbyid ('inputb'). Value, // Params
Onrequestcomplete // Complete Event
);
Return false;
}
Function onrequestcomplete (result)
{
Alert (result );
}
</SCRIPT>
4. The page after running is as follows:
Test the Web service in master-page:
Test the Web service in content-page:
The scriptmanagerproxy is introduced here. The question is, in my ide, why does scriptmanagerproxy always prompt that it is an unknown element, but it does not run correctly and the result can also be displayed?