RIA Development Center
Features Tips Events
Delivering business processing logic through RIA (Rich Internet Application) format is very attractive to architects, developers and operators of IT shops. RIA combines the richness of the desktop application with the ease of deployment, ubiquity and platform independence of the web application. RIAs in the form of mashups, are very popular in the consumer space but have yet to see similar success in the enterprise space. Enterprise applications are stateful and process-centric in nature. Read more
See more tips
Get regular email alerts when we publish new features!
DevX RIA Development Update

More Newsletters
How to Construct a Reusable Silverlight ASP.NET User Control (cont'd)
More Resources
  • MSDN Evaluation Center: Microsoft Visual
        Studio 2005
  • Microsoft Silverlight Software Development Kit
  • The ASP.NET User Control

    User controls generally are created when there is a need for reusable content. A corporate logo is an item that could conceivably be used numerous times throughout the course of an application. Additionally, if the need arises to use a control across applications, the user control's sibling, the custom control, may be a more appropriate alternative. Reusability is recursively responsible.

    The ASP.NET markup code for the corporate logo user control is defined below. In this specific instance, the code-behind has been intentionally omitted. However, that is because there is no procedural code to mention. At the end of this article, you will find a zip file containing the source code for this example. Please examine the code for yourself.

    <%@ Control Language="C#" AutoEventWireup="true"
     CodeBehind="CorporateLogo.ascx.cs"
     Inherits="SilverlightUserControl.CorporateLogo" %<
    
    <div id=<%= "\"silverlightHost" + this.ID + "\"" %>>
    
    
       <script type="text/javascript" src="js/CreateSilverlight.js">
       </script>
       <script type="text/javascript" src="js/Silverlight.js"></script>
    
       <script type="text/javascript">
            // Reference the HTML element that hosts the Silverlight
            // content
            var htmlElement =
               document.getElementById(<%= "\"silverlightHost" +
                                        this.ID + "\"" %>);
    
            // Create the Silverlight control
            Sys.Silverlight.createObject
            (
                "CorporateLogo.xaml",
                htmlElement,
                <%= "\"silverlight" + this.ID + "\""  %>,
                {
                    width:'50',
                    height:'50',
                    inplaceInstallPrompt:false,
                    background:'white',
                    isWindowless:'false',
                    framerate:'30',
                    version:'0.9'
                },
                {
                    onLoad:null
                },
                null
            );
    
    
    
       </script>
    </div>
    

    The key item in this code snippet is the utilization of the value of the user control's "ID" property. The "ID" property of the user control is utilized in:

    • Assigning the "id" attribute of the hosting DIV element
    • Referencing the hosting DIV element within the instantiation of the Silverlight control
    • Defining the ID of the Silverlight control

    This is important because it ensures unique references of the Silverlight content. To illustrate why this is needed, envision creating a Web page that requires the use of the corporate logo multiple times. Without the unique names, there would be no way to distinguish between the various instances of the logo.

    Conclusion

    At this point, a very basic user control that utilizes Silverlight has been constructed. This user control demonstrated how to integrate Silverlight content with a Web application. It also demonstrated how one can leverage an existing skillset to harness the power of a new technology.

    Silverlight provides new avenues for building lasting connections with users. It's important to grow these connections with minimal effort. With Silverlight, it's easy to strengthen your brand leveraging your existing Web applications.

    * This article originally appeared on CodeGuru.

    Previous Page: Introduction  
    Page 1: IntroductionPage 2: The ASP.NET User Control
    We have a winner in the RIA Run contest! Check out the Contest Winners Gallery and see which entries took the top prizes. You can play the games, too! Also, be sure to check out our interview with the grand prize winner to see how he crafted his winning entry. (Silverlight 2 Beta 2 required)