Call Web Service in ASP. Net Atlas -- call web service during page loading

Source: Internet
Author: User
Author: dflying Chen (http://dflying.cnblogs.com /)

Most of the time, we need to call someWeb ServiceFor exampleAtlas listviewWill be immediately loadedGet the initial filling data. Although this can be usedAtlasOfInitialdataControls are completed, but for some other requirements, such as executingAtlasScript (whereAtlasPairJavascript), We still need a page loading event to trigger these operations.

Many of my friends use the following two methods:

    1. Directly on the pageScriptThe script to be executed.
    2. InOnload JavascriptEvent processing method.

These are incorrect methods, and errors may occur, for a simple reason:AtlasClient implementation is alsoJavascriptThe statement of the preceding two methods isAtlasClient implementation runs before initialization, which naturally leads to errors.

AtlasFully aware of this demand and providesFrameworkInternalOnloadEvent.Atlas frameworkTriggered after initialization. To capture this event, you needAtlas XML scriptStatement:

< Page Xmlns: script = "Http://schemas.microsoft.com/xml-script/2005" >
< Components >
< Application ID = "Application" Load = "Onapplicationload"   />
</ Components >
</ Page >

WhereApplicationAs the currently runningAtlasProgramProvidesLoadEvent, so that we canAtlas frameworkAfter initialization, execute ourCode.

The following is an example,Web ServiceThe following is a simple addition of two numbers:

[Webmethod]
Public   Int Addint ( Int Int1, Int Int2)
{
ReturnInt1+Int2;
}

ThenAspxAddScriptmanagerAndWeb ServiceReference:

< Atlas: scriptmanager ID = "Scriptmanager" Runat = "Server" Enablescriptcomponents = "True" >
< Services >
< Atlas: servicereference Path = "Simplewebservice. asmx"   />
</ Services >
</ Atlas: scriptmanager >

Add two moreInputIt is used to provide two addition numbers:

< Input ID = "Value1" Type = "Text" Value = "1"   />
< Input ID = "Value2" Type = "Text" Value = "2"   />

Add captureAtlas framework LoadEventXML scriptDefinition:

< Script Type = "Text/XML-script" >
< Page Xmlns: script = "Http://schemas.microsoft.com/xml-script/2005" >
< Components >
< Application ID = "Application" Load = "Onapplicationload"   />
</ Components >
</ Page >
</ Script >

The following are the event processing functions and their correspondingCallback, We can see three types of applicationsAtlas frameworkProvided extensions:

    1. $ ()Method, equivalentDocument. getelementbyid ()
    2. SYS. UI. textboxClass, encapsulatedHtmlOfInputElement
    3. PairWeb ServiceCalledMashup
Function Onapplicationload ()
{
VaR Value1 =   New SYS. UI. Textbox ($ ('value1 '));
VaR Value2 =   New SYS. UI. Textbox ($ ('value2 '));
Dflying. simplewebservice. addint (
Value1.get _ text (),
Value2.get _ text (),
Oncomplete
);
Return   False ;
}

Function Oncomplete (result)
{
Alert (result );
}

Running result, no problem:

TheSource codeDownload here: http://files.cnblogs.com/dflying/ApplicationLoadEventDemo.zip

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.