views:

75

answers:

2

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.

+3  A: 

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.

RPM1984
+1: Beat me to it, and more clear/elegant to boot. Thanks.
kbrimington
@kbrimington. =)
RPM1984
I tried your suggestion but I am still receiving the error. Actually when I go to use that registered control, IPAMControl does not show up within Intellisense. and the link you referenced is the exact one I was referencing for this :)
mattgcon
@mattgcon - i have multiple registrations in my web config like my answer. Try removing all of the user control declarations, make sure the website runs (this ensures something else isnt causing problems). then add the controls in one by one.
RPM1984
remove all the user control declarations from all the pages correct?
mattgcon
Im very frustrated, I removed the user control declarations from one ofthe pages and I cannot see <IPAMControl:track. What am I doing wrong?
mattgcon
are you getting the error in the web.config file, or the pages that you are trying to add it? I meant remove all the declarations from the web.config, get your website/pages working, then go from there.
RPM1984
I am receiving the errors on the individual pages, not in the web.config file. Either I receive an Element is not known element error (on individual page) or I receive the Invalid or missing attribute error message (when they are in the web.config file)
mattgcon
okay - so once you fix up the web.config (like in my answer), create a simple ASPX page. no master page, nothing. simple. then, include the control like in my answer. does that work? (when i get bugs like this, i try to eliminate all dependencies/other code from getting in the way)
RPM1984
No this is not working either, I created a simple aspx page, nothing was put into it but <%@ Register TagPrefix="myControl" TagName="header" Src="~/Controls/header.ascx" %>and it still didnt work
mattgcon
whoah hold on. dude, you dont need to register the control again in the ASPX thats the whole POINT of adding it to the web.config. =)
RPM1984
when i say "include the control", i mean include the HTML of the control (IPAMControl:track), not register it again.
RPM1984
Oh I thought that you said remove them from the webconfig file? oh sorry my fault. I will try it right now
mattgcon
I just tried it and I am getting the Element in not known error that I was getting originally
mattgcon
So isolating just the user control on a aspx page doesn't work. What could be the next step
mattgcon
@mattgcon - see my edit. i took the time and created a web app illustrating how to do it (works fine), see my steps. if that doesnt help, unfortunately im not sure what else can.
RPM1984
RPM2984 - Thank you for your time and effort. The web application was originally a web site, created by someone who had no business developing any type of web site. I have successfully converted numerous websites to web apps, but this one, hey Im no mirical worker. I decided to give up on this effort for right now as the overall project was taking way too much time off of other projects I had. I have tried all of your suggestions and the last thing you said in your edit seems to be true "There is something else wrong with the web app somewhere else" Thank you again
mattgcon
No problems, good luck - im sure you'll sort it out eventually (it'll be something simple, it always is).
RPM1984
A: 

abandond this issue

mattgcon