Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic custom server control question

Status
Not open for further replies.

sds814

Programmer
Feb 18, 2008
164
US
I'm using VS2012. I'm trying to follow an exercise from a book.

Here is the code for my custom server control:
Code:
namespace ServerControl
{
    [ToolboxData("<{0}:menucustomcontrol runat=\"server\"></{0}:menucustomcontrol>")]
    public class MenuCustomControl : Control
    {
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);

            writer.WriteLine("<div>");
            RenderMenuItem(writer, "Apress", "[URL unfurl="true"]http://www.apress.com");[/URL]
            writer.Write(" | ");
            RenderMenuItem(writer, "Microsoft", "[URL unfurl="true"]http://www.microsoft.com");[/URL]
            writer.Write(" | ");
            RenderMenuItem(writer, "MSDN", "[URL unfurl="true"]http://msdn.microsoft.com");[/URL]
            writer.Write(" | ");
            RenderMenuItem(writer, "ASP.NET", "[URL unfurl="true"]http://asp.net");[/URL]
            writer.Write("</div>");
        }

        private void RenderMenuItem(HtmlTextWriter writer, string title, string url)
        {
            writer.Write("<span><a href=\"");
            writer.Write(url);
            writer.Write("\">");
            writer.Write(title);
            writer.WriteLine("</a><span>");
        }
    }
}

I've added the reference to ServerControl.dll in the web application project. After adding ServerControl to the toolbox and dragging the control to the aspx page, the code looks like:
Code:
<%@ Page Title="Simple User Control Demo" Language="C#" MasterPageFile="~/SimpleUserControl.Master" AutoEventWireup="true" CodeBehind="SimpleUserControl.aspx.cs" 
    Inherits="SimpleUserControl.SimpleUserControl1" %>
<%@ Register TagPrefix="apress" Namespace="ServerControl" Assembly="ServerControl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <apress:MenuCustomControl ID="Menucustomcontrol1" runat="server"></apress:MenuCustomControl>
</asp:Content>

The error I get is when compiling the web application on SimpleUserControl.aspx.designer.cs:

The type or namespace name 'ServerControl' could not be found in the global namespace (are you missing an assembly reference?)

I'm not sure what I'm doing wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top