ASP.NET用户控件不初始化子控件 [英] ASP.NET UserControl Does Not Initialize Child Controls

查看:146
本文介绍了ASP.NET用户控件不初始化子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页,我有以下几点:

Inside my page, I have the following:

<aspe:UpdatePanel runat="server" ID="updatePanel">
    <ContentTemplate>
        <local:KeywordSelector runat="server" ID="ksKeywords" />
    </ContentTemplate>
</aspe:UpdatePanel>

KeywordSelector 控制是控制我在同一个组件定义和本地映射到它的命名空间。

The KeywordSelector control is a control I define in the same assembly and local is mapped to its namespace.

的控制是由其他几个控制的和被定义为这样的:

The control is made up of several other controls and is defined as such:

<%@ Control Language="C#" AutoEventWireup="true"
            CodeBehind="KeywordSelector.ascx.cs"
            Inherits="Keywords.KeywordSelector" %>

和拥有自己相当多的服务器控件,都定义为了.Designer.cs 文件成员。

and has quite a few server controls of its own, all defined as members in the .designer.cs file.

不过,控件的生命周期的任何部分在它有任何的子控件对象也不会产生HTML

  1. 所有的了.Designer.cs 文件中定义的成员是
  2. 拨打 HasControls 返回
  3. 拨打 EnsureChildControls 无能为力。
  4. 控件集合为空。
  1. All of the members defined in the .designer.cs file are null.
  2. Calls to HasControls return false.
  3. Calls to EnsureChildControls do nothing.
  4. The Controls collection is empty.

删除的UpdatePanel 确实没有好。我试图用重现它在一个干净的页面上一个新的用户控件键,同样的事情发生。

Removing the UpdatePanel did no good. I tried to reproduce it in a clean page with a new UserControl and the same thing happens.

我使用ASP.NET在.NET Framework 3.5 SP1中通过集成式Web服务器。

I am using ASP.NET over .NET Framework 3.5 SP1 with the integrated web server.

我是什么在这里失踪?

更新#1:以下罗布的评论,我看着的OnInit 并发现用户控件没有检测到有任何子控件。此外, CreateControlCollection 永远不会被调用!

Update #1: Following Rob's comment, I looked into OnInit and found that the UserControl does not detect that it has any child controls. Moreover, CreateControlCollection is never called!

推荐答案

嗯,我已经找到了(S)的问题:

Well, I've found the problem(s):

  1. 用户控制的,而不是的自定义控件的必须注册一个接一个在的web.config 的文件。做到这一点:

  1. User Controls, as opposed to Custom Controls must be registered one-by-one in the web.config file. Do this:

&LT;添加标签preFIX =本地变量名=KeywordSelectorSRC =〜/ KeywordSelector.ascx/&GT;

来代替:

&LT;添加标签preFIX =本地命名空间=关键词集结号=关键词/&GT;

您永远不应该将的WebControl 在相同的目录控制正在使用它。这是彻头彻尾的愚蠢。 在这里阅读有关

You should never place a WebControl in the same directory as the Control that is using it. This is downright silly. Read about it here.

感谢您的帮助。现在,如果我能记住我自己的答案是的答案...

Thanks for the help. Now if only I could mark my own answer as the answer...

这篇关于ASP.NET用户控件不初始化子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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