I'm using VS2012. I'm trying to follow an exercise from a book.
Here is the code for my custom server control:
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:
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.
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.