Using User Control

It took nearly entire morning to figure out where was the actual fault! I tried first in my Laptop, and the user control did not work.

Next I tried in my GrandPa. The old AMD Athlon desktop that has been assisting me to do everything that I could have imagined since seven years.

The page looks like this:

User Control in ASP.NET is extremely important in case when developer wants to use a control repeatedly in many pages, it can just be dragged down from the solution explorer.

Now I’ll come to the code part:

<uc1:SectionLevelTutorialListing ID=”SectionLevelTutorialListing1″
runat=”server” />

  • This elements come automatically to the Default.aspx.
  • Next Code of creating User Control:
  • <%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”SectionLevelTutorialListing.ascx.cs” Inherits=”UserControls_SectionLevelTutorialListing” %>
    <asp:Repeater ID=”TutorialList” runat=”server” EnableViewState=”False”>
    <li><asp:HyperLink ID=”HyperLink1″ runat=”server”
    NavigateUrl='<%# Eval(“Url”) %>’
    Text='<%# Eval(“Title”) %>’></asp:HyperLink>
    – <%# Eval(“Description”) %></li>
  • The next part of Data Binding the User Control to the SiteMap.:
  • protected void Page_Load(object sender, EventArgs e)
    // If SiteMap.CurrentNode is not null,
    // bind CurrentNode ChildNodes to the GridView
    if (SiteMap.CurrentNode != null)
    TutorialList.DataSource = SiteMap.CurrentNode.ChildNodes;


    The actual code and everything I got from Scott Mitchel’s very useful database tutorial.

  • Read Scott Mitchel


    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s