Silverlight integrates ajax to achieve front-end and back-end Data Interaction

Source: Internet
Author: User

By accident, the company originally stressed the use of WCF for project approval. WPF/e enhanced the user experience. Due to my ignorance and laziness, I came up with a naive idea: using WPF/E for approval is not a two-pronged process.
The following describes how to use Silverlight (Microsoft renamed WPF/E as Silverlight in September) to integrate Ajax into the approval process. The approval process on the page consists of three parts: department approval, Science and Technology Department approval, and Director approval. The function is to customize the approval process. For example, the approval process is department approval-> Director approval, or the approval process can be customized to the Science and Technology Department-> Director approval. The custom data is stored in the background XML file.
Front-end Silverlight presentation layer Language XAML, back-end server scripting language C #, data storage format XML, intermediate data transmission technology Ajax.
The method for embedding Silverlight page in. NET is to call JS functions in aspx to pass the path of the XAML file relative to the server, as follows: CopyCode The Code is as follows: <Div style = "width: 662px; Height: 622px" id = "silverlightcontrolhost">
<SCRIPT type = "text/JavaScript"> <! --
Createsl ('workflow. XAML ');
// --> </SCRIPT>
</Div>

The function calls the createobjectex method of Silverlight to specify the XAML source, parentelement, and events. The Code is as follows:Copy codeThe Code is as follows: function createsl (xamlpage)
{
Silverlight. createobjectex ({
Source: xamlpage,
Parentelement: Document. getelementbyid ("silverlightcontrolhost "),
ID: "silverlightcontrol ",
Properties :{
Width: "100% ",
Height: "100% ",
Version: "1.1 ",
Enablehtmlaccess: "true"
},
Events :{
Onload: onloaded
}
});
// Give the keyboard focus to the Silverlight control by default
Document. Body. onload = function (){
VaR silverlightcontrol = Document. getelementbyid ('silverlightcontrol ');
If (silverlightcontrol)
Silverlightcontrol. Focus ();
}
}

The work to be done is to register the [Scriptable] presentation layer WPF class (originally CAVAS) in the xaml backend CS file as a scripted object (registerscriptableobject) and event, and set the event in the presentation layer in JS events. The implementation method is as follows:
XAML code:
[Scriptable]Copy codeThe Code is as follows: public partial class workflow: canvas
{
Public workflow ()
{
Webapplication. Current. registerscriptableobject ("wpfe", this );
}
......
[Scriptable]
Public event eventhandler workflowfunc;
}

JS Code:Copy codeThe Code is as follows: function onloaded (sender, argS)
{
Sender. content. wpfe. workflowfunc = onworkflow;
}

In addition, if JS calls the scripted function in XAML, the method is
Var control = Document. getelementbyid ("silverlightcontrol ");
VaR onreturnwfresult = control. content. wpfe;
Ajax technology is used to transmit data in XAML to the background for processing. In this example, XMLHttpRequest is defined in the onworkflow event, and then the data is transmitted to the background through this Ajax object. In this example, the background scripting language is C # And the data receiving method is request. Params.

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.