October 21, 2016
Hot Topics:

How to Construct a Reusable Silverlight ASP.NET User Control

  • May 4, 2007
  • By Chad A. Campbell
  • Send Email »
  • More Articles »

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"
 Inherits="SilverlightUserControl.CorporateLogo" %<

<div id=<%= ""silverlightHost" + this.ID + """ %>>

   <script type="text/javascript" src="js/CreateSilverlight.js">
   <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
            <%= ""silverlight" + this.ID + """  %>,

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.


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.

Download the Code

Download the zip file that contains all the code for this article here.

About the Author

Chad Campbell (MCSD, MCTS) is a solutions developer for mid- to large-sized organizations. He is a thought leader with Crowe Chizek in Indianapolis, Indiana. Chad specializes in Web-based solutions, Reach him at cacampbell@crowechizek.com.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel