【发布时间】:2009-02-13 07:08:29
【问题描述】:
我正在尝试实现一些谷歌无法给出答案的事情。我正在尝试创建一个 asp.net 用户控件,当我将内容放入其中时,它的打开关闭标签将包含它,以便我仍然能够通过父 ID 访问它的内容。这是我想要实现的一个示例。
用户控制:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctrlGENE_CollapsiblePanel.ascx.cs"
Inherits="Controls_GenericsControls_ctrlGENE_CollapsiblePanel" %>
<asp:Panel ID="pnlHeader" CssClass="SnapPanelHeader" runat="server">
<h3>
<asp:Literal ID="litTitle" Text='<%# Text %>' runat="server" />
</h3>
<div class="SnapPanelHeader-img">
<img id="imgOpenClose" src="/images/application/close.jpg" alt="" />
</div>
</asp:Panel>
<asp:PlaceHolder runat="server" ID="pnlContent">
// **HERE I WANT TO INCLUDE THE INSIDE MARKUP**
</asp:PlaceHolder>
<act:CollapsiblePanelExtender runat="server" TargetControlID="pnlContent" ImageControlID="imgOpenClose"
ExpandControlID="imgOpenClose" CollapseControlID="imgOpenClose" CollapsedImage="/images/application/open.jpg"
ExpandedImage="/images/application/close.jpg" CollapsedSize="0" TextLabelID="litTitle">
</act:CollapsiblePanelExtender>
包含控件的父页面:
<uc:MyUserControl ID="clpTest" runat="server">
<asp:Literal ID="litText" runat="server" />
</uc:MyUserControl>
这样我就可以在 Parent.cs 文件中做:
litText.Text = "Anything";
我知道我们可以实现与 ITemplate 接口类似的东西,如下所示:http://msdn.microsoft.com/en-us/library/36574bf6.aspx
看起来像这样:
<uc:MyUserControl ID="clpTest" runat="server">
<ItemTemplate>
<asp:Literal ID="litText" runat="server" />
</ItemTemplate>
</uc:MyUserControl>
但如果我这样做,我将无法访问 litText 的属性,而我可以访问它的唯一方法是使用 FindControl,我想避免这种情况。
如果我能以一种或另一种方式达到我的目标,有人对此有提示吗?
谢谢
【问题讨论】:
-
最终目标是什么?这个解决方案可能对你需要的来说太复杂了
标签: c# asp.net user-controls