smartcaveman smartcaveman - 1 year ago 63
ASP.NET (C#) Question

How to register custom server control on ASP.NET page

I have a project and I am trying to register a custom server control (there is no

file) on the page. I am currently using

Class Declaration

namespace MyApp.Controls{
public class CustomControl: WebControl{
public string Text
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
ViewState["Text"] = value;
protected override void RenderContents(HtmlTextWriter output)

On my page,

<%@ Register TagPrefix="myControls" Namespace="MyApp.Controls" %>
<myControls:CustomControl runat="server" Text="What up!" />

I receive a Parser Error, with the message "Unknown server tag 'myControls:CustomControl'."

What am I doing wrong?

Answer Source

Well, if this control is in another class library, or even if it's in the same one, it wouldn't be a bad idea to specify control's assembly in @Register:

<%@ Register TagPrefix="myControls" Namespace="MyApp.Controls" Assembly="MyApp" %>
   <myControls:CustomControl runat="server" Text="What's up!" />

Clean and rebuild your solution too in order to verify everything is compiled rightly!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download