Sunday, 13 January 2013 13:56

how to add silverlight application to a asp.net application

Written by 
Rate this item
(0 votes)

silverlight application are great.you can add silverlight
application in your asp.net project easily.follow the
steps and you will know how to create and add silverlight
applicaiton in asp.net application/website -

1.first create a asp.net application project from visual studio
2008/2010.

2.now create a aspx page(silverlight application test page) and
add the following codes in your page after page directive -

<!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" >
<head id="Head1" runat="server">
<title>SilverlightApplication1</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
#silverlightControlHost {
height: 100%;
text-align:center;
}
</style>
<script type="text/javascript" src="/Silverlight.js"></script>
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}

var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;

if (errorType == "ImageError" || errorType == "MediaError") {
return;
}

var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

errMsg += "Code: " + iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";

if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
</head>
<body>
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," width="100%" height="100%"
type="application/x-silverlight-2">
<param name="source" value="ClientBin/SilverlightApplication1.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="WHite" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
</object></div>
</form></body>
</html>

here - <param name="source" value="ClientBin/SilverlightApplication1.xap"/>
includes the silverlight application name as SilverlightApplication1.

3.download the-
http://www.adefwebserver.com/DotNetNukeHELP/Misc/Silverlight/HelloWorld3/files/Silverlight.js
file and place it in your application's root directory.

4.now From the Menu, select File->Add->New Project...
Create a Silverlight Application named "SilverlightApplication1".
you will see a new silverlight application window.
there check the option-"host the silverlight application
in a new or existing website in the solution" in VS 2010.
you may find a different option in VS 2008.then click ok
and a sliverlight application will be added to the
solution explorer.

5.after adding content in your silverlight application
build the solution.you will see SilverlightApplication1.xap
added in the ClientBin directory in your asp.net application
project.

6.run the test page you created in step-2 to view
your silverlight application.

Read 2865 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.