Adding load and error events to Silverlight at initialization time
The events parameter allows you to specify functions that are executed on certain events during the Silverlight application initialization. Currently, Silverlight allows you to register handlers for onLoad and onError events. The following code snippet creates a Silverlight object that implements onLoad and onError event handling:
<script type="text/javascript">
function createSilverlight() {
Silverlight.createObjectEx({ source: "Page.xaml", parentElement: document.getElementById("SLHost"), id: "SilverlightControl", properties: {
width: "400", height: "400", version: "1.1", background: "#1111FF"
onLoad:silverlightLoad, onError:silverlightError
function silverlightLoad(control, userContext, sender) {
alert("Silverlight successfully rendered.");
function silverlightError(control, userContext, sender)
alert("The browser encountered an error rendering Silverlight.");
Notice that the event parameter defines the event handler by using the event: handlerfunction syntax. If the onError event is raised, then the silverlightError handler function is called and simply displays an alert message that indicates an error was encountered. If the onLoad event is raised, meaning that the page loaded successfully, then the silverlightLoad handler function is called and simply displays an alert message that indicates the page loaded successfully. Using event handlers at initialization time enables you to be more dynamic with your Silverlight applications.
Post a comment