Silverlight Fusion Ajax to achieve front and back data interaction _ practical skills

Source: Internet
Author: User
Tags silverlight
Things happened accidentally, the company emphasized is the use of WCF to do project approval process, wpf/e enhance the user experience; because of personal ignorance and lazy, I have a naïve idea: use wpf/e to do approval process, this is not two birds with one stone.
The following is an approval process that blends Ajax with Silverlight (Microsoft renamed wpf/e to Silverlight in September 07). The approval process on the interface from the bottom up includes 3 parts, department approval, Science and Technology department approval, factory director approval. Implementation of the function can be customized approval process, such as approval process is the department approval--> director approval, can also be made into science and technology department approval--> director approval. The custom data exists in the background XML file.
Foreground Silverlight Presentation layer language XAML, background Server scripting language C #, data storage format XML, intermediate data transfer technology Ajax.
. NET, the method of embedding the Silverlight Page in ASPX is to call the JS function to pass the path of the XAML file relative to the server, as follows:
Copy Code code as follows:

<div style= "width:662px;height:622px" id= "Silverlightcontrolhost" >
<script type= "Text/javascript" ><!--
Createsl (' Workflow.xaml ');
--></script>
</div>

The function invokes the createObjectEx method of Silverlight to specify XAML source, Parentelement, events, and so on, and the corresponding code is as follows:
Copy Code code 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 is also done in the XAML background CS file [scriptable] presentation layer WPF class (originally Cavas), the class is registered as a scriptable object (RegisterScriptableObject) and scriptable event, and in JS events To set the event in the presentation layer, the following methods are implemented:
XAML Code:
[Scriptable]
Copy Code code as follows:

public partial class Workflow:canvas
{
Public Workflow ()
{
WebApplication.Current.RegisterScriptableObject ("Wpfe", this);
}
......
[Scriptable]
public event EventHandler Workflowfunc;
}

JS Code:
Copy Code code as follows:

function onloaded (Sender,args)
{
Sender. Content.wpfe.workflowFunc = Onworkflow;
}

In addition, if JS calls a scriptable function in XAML, the method is
var control = document.getElementById ("Silverlightcontrol");
var Onreturnwfresult = control. CONTENT.WPFE;
The AJAX technique is used to transfer data from XAML to background processing, in this case defining the XMLHttpRequest in the Onworkflow event, and then passing the data to the background through the Ajax object. The background scripting language in this example is C # and the data reception 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.