Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows XP

Silverlight and ASP.NET : Adding Silverlight Content to a Web Page

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
8/5/2011 6:25:25 PM
You can add Silverlight content to a Web page in three ways. The first is to use the traditional <object> tag embedded in HTML. Second, you can use the ASP.NET server-side control for hosting Silverlight content. Finally, you can add Silverlight content dynamically using some JavaScript. Begin by adding content using the <object> tag.

1. Using the Object Tag

The first way to add Silverlight content is by using the standard <object> tag (the one that loaded ActiveX controls on pages written in the late 1990s!). In fact, Visual Studio creates an HTML page for you that loads the Silverlight content using the <object> tag.

<body>
<!-Run-time errors from Silverlight will be displayed here. -->
<!-- This will contain debugging information and should be removed -->
<!-- or hidden when debugging is completed -->
<div id='errorLocation' style="font-size: small;color: Gray;"></div>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2,"
type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightSite.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=124807"
style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181"
alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'>
</iframe>
</div>
</body>


Silverlight is implemented as an ActiveX control for Windows clients and as a Safari browser plug-in for Macintosh clients. The <object> tag looks up the Silverlight implementation on the client computer, and then fetches the appropriate XAP file from the server and hosts it. Notice how parameters can be passed to Silverlight. The ones listed previously are predefined, but you can define your own parameters to be passed into Silverlight when it loads.

2. Using the ASP.NET Silverlight Server-Side Control

The second way to include Silverlight content on your page is to use the ASP.NET server-side control that generates the object tag for you when it renders. Visual Studio creates a page using the ASP.NET Silverlight control.

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="System.Web.Silverlight"
Namespace="System.Web.UI.SilverlightControls"
TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
<title>SilverlightORama</title>
</head>
<body style="height:100%;margin:0;">
<form id="form1" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div style="height:100%;">
<asp:Silverlight ID="Xaml1" runat="server"
Source="~/ClientBin/SilverlightSite.xap"
MinimumVersion="2.0.31005.0" Width="100%"
Height="100%" />
</div>
</form>
</body>
</html>


The Silverlight control works much the same way as all of the other server-side controls work. They end up in the page's control tree and send HTML to the browser. The Silverlight control emits the HTML necessary to allow the client browser to load Silverlight and host the content in it.

3. Using the JavaScript Function

Visual Studio also includes a JavaScript library with a helper function—Silverlight.createObjectEx. You can find it in the Silverlight.js file included as part of the ASP.NET test project produced by Visual Studio. Call Silverlight.createObjectEx from within the HTML page and pass in the path to the XAP file, the events, and any other parameters important to the Silverlight control. Although this is less convenient than is using the server-side control, it offers you the ability to invoke Silverlight content dynamically—for example, by way of a JavaScript event.
Other -----------------
- Silverlight and ASP.NET : XAML
- Silverlight and ASP.NET : Creating a Silverlight Application
- Microsoft ASP.NET 4 : Developing a Web Part
- Microsoft ASP.NET 4 : The Web Parts Architecture
- Microsoft ASP.NET 4 : Handlers and Session State & Generic Handlers (ASHX Files)
- Microsoft ASP.NET 4 : HTTP Handlers - Handlers and IHttpHandler
- Microsoft ASP.NET 4 : HTTP Handlers - The Built-in Handlers
- Microsoft ASP.NET 4 : ASP.NET Request Handlers
- Microsoft ASP.NET 4 : HttpModules (part 2) - Seeing Active Modules & Storing State in Modules
- Microsoft ASP.NET 4 : HttpModules (part 1) - Existing Modules & Implementing a Module
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer