ASP. NET Ajax entry-level series: using the scriptmanagerproxy Control

Source: Internet
Author: User

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?

 

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.