注册自定义控件失败 [英] Registering custom controls fails

查看:156
本文介绍了注册自定义控件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在webconfig文件中注册我的用户控件,因为我收到的元素不存在错误,但我收到以下错误,当我尝试在webconfig注册他们:

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'

以下是webconfig文件中的code:

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>

这是遇到此问题的页面也引用MasterPages如果该事项在所有:

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.

请帮忙。

推荐答案

摆脱命名空间属性,因为它混淆ASP.NET,是否你试图注册一个用户控件或自定义控件。

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.

用户控制:

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

自定义控制:

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

所以,在你的例子:

So, in your example:

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

而在ASPX / ASCX,你用这样的:

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

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

请参阅here获取更多信息。

修改

要证明这个作品 - 我做了以下内容:

To prove this works - i did the following:


  1. 创建新的Web应用程序

  2. 在Web应用程序的根目录下创建一个名为控件的新文件夹

  3. 增加了新的Web用户控件称MyUserControl.ascx

  4. 修改web.config中添加控制登记

  5. 修正的Default.aspx添加控件。

而这一切都工作正常。

下面是用户控制:

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

下面是在web.config我编辑的部分:

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

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

下面是Default.aspx的变化我做:

Here is the Default.aspx change i made:

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

和页面正确呈现。

现在,除非我在这里做的是你如何试图做到这一点不同,你必须有一个与此干扰其他code /错误。

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.

这篇关于注册自定义控件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆