Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering custom controls fails

I am attempting to register my user controls within the webconfig file because I am receiving the Element does not exist error, but I am receiving the following error when I try to register them in webconfig:

Invalid or missing attributes found in the tagPrefix entry. For user control, you must also specify 'tagName' and 'src'. For custom control, you must also specify 'namespace', and optionally 'assembly'

The following is the code within the webconfig file:

<pages>
  <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="IPAMControl" tagName="contact_us" namespace="IPAM.Website.Controls" src="~/controls/contact_us.ascx" />
    <add tagPrefix="IPAMControl" tagName="erh_list" namespace="IPAM.Website.Controls" src="~/controls/erh_list.ascx" />
    <add tagPrefix="IPAMControl" tagName="header" namespace="IPAM.Website.Controls" src="~/controls/header.ascx" />
    <add tagPrefix="IPAMControl" tagName="footer" namespace="IPAM.Website.Controls" src="~/controls/footer.ascx" />
    <add tagPrefix="IPAMControl" tagName="main_tnavbar" namespace="IPAM.Website.Controls" src="~/controls/main_tnavbar.ascx" />
    <add tagPrefix="IPAMControl" tagName="program_header" namespace="IPAM.Website.Controls" src="~/controls/program_header.ascx" />
    <add tagPrefix="IPAMControl" tagName="program_list" namespace="IPAM.Website.Controls" src="~/controls/program_list.ascx" />
    <add tagPrefix="IPAMControl" tagName="signup_section" namespace="IPAM.Website.Controls" src="~/controls/signup_section.ascx" />
    <add tagPrefix="IPAMControl" tagName="speaker_list" namespace="IPAM.Website.Controls" src="~/controls/speaker_list.ascx" />
    <add tagPrefix="IPAMControl" tagName="track" namespace="IPAM.Website.Controls" src="~/controls/track.ascx" />
  </controls>
</pages>

The pages that are having this issue are also referencing MasterPages if that matters at all:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/programs/MasterProgram.master" CodeBehind="~/programs/wim2011/default.aspx" Inherits="IPAM.Website.programs.wim2011._default" %>

and they are each within their own folders.

Please help.

like image 924
mattgcon Avatar asked Aug 04 '26 06:08

mattgcon


1 Answers

Get rid of the namespace attribute, as it's confusing ASP.NET as to whether you're attempting to register a User Control or a Custom Control.

User Control:

<add tagPrefix="SomeTagPrefix" src="~/Controls/SomeControl.ascx" tagName="SomeTagName"/>

Custom Control:

<add tagPrefix="SomeTagPrefix" namespace="SomeNamespace" assembly="SomeAssembly"/>

So, in your example:

<add tagPrefix="IPAMControl" tagName="track" src="~/controls/track.ascx" />

And on the ASPX/ASCX, you use it like this:

<IPAMControl:track id="ipamTrack" runat="server" />

See here for more info.

EDIT

To prove this works - i did the following:

  1. Create new Web Application
  2. Create new folder called "Controls" in the root of the web application
  3. Added a new "Web User Control" called "MyUserControl.ascx"
  4. Modified web.config to add registration of control
  5. Modified Default.aspx to add the control.

And it all works fine.

Here is the User Control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="WebApplication1.Controls.MyUserControl" %>
<span>Hi, im a user control, how are you?</span>

Here is the portion of the web.config i edited:

<pages>
      <controls>
        <add tagPrefix="MyControls" tagName="MyUserControl" src="~/Controls/MyUserControl.ascx"/>
      </controls>
    </pages>

Here is the Default.aspx change i made:

<MyControls:MyUserControl id="myUserControl" runat="server" />

And the page rendered correctly.

Now, unless what i have done here is different to how you have attempting to do it, you must have other code/errors that is interfering with this.

Don't know how much else help i can be.

like image 142
RPM1984 Avatar answered Aug 05 '26 23:08

RPM1984