繁体   English   中英

如何以声明方式将ASP.NET UserControl的public属性传递给子UserControl

[英]How do I Declaratively pass a ASP.NET UserControl's public property to a child UserControl

我正在尝试清理工作中的旧ASP.NET应用程序...

我有一个名为FailedBatchPanel.ascx的父用户控件,其定义如下:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FailedBatchPanel.ascx.cs" Inherits="Controls_FailedBatchPanel" %>
<%@ Register TagPrefix="dashboard" TagName="FailedBatch" Src="~/Controls/FailedBatchControl.ascx" %>
<%@ Import Namespace="System" %>

<div class="panel panel-default" id="failedBatchesPanel">
  <div class="panel-heading">
    <h4 class="panel-title">
      <a class="accordion-toggle" data-toggle="collapse" 
         <data-parent="#<%=ParentId %>" href="#<%=PanelId %>">
        <%=Title %>
      </a>
    </h4>
  </div>
</div>
<div id="<%=PanelId %>" class="panel-collapse collapse">
  <div class="panel-body">
    <dashboard:FailedBatch runat="server" 
      ID="failedClaims" 
      BatchType='<%$ Code: BatchType %>'/>
  </div>
</div>

子控件是FailedBatch.ascx ,仅包含具有数据绑定的asp:Repeater。

父控件FailedBatchPanel的调用方式如下:

<dashboard:FailedBatchPanel runat="server" 
    Title="SomeTitle" 
    ParentId="categories" 
    PanelId="collapseOne" 
    BatchType="goober"/>

我想将以声明方式定义的BatchType传递给FailedBatchPanel中嵌入的子控件。

从上面的示例中可以看到,我尝试使用InfinitiesLoop在http://weblogs.asp.net/infinitiesloop/archive/2006/08/定义的`<%$ Code:...%> CodeExpressionBuilder 09 /在-CodeExpressionBuilder.aspx

在我尝试过的每种情况下,FailedBatch中定义的BatchType公共属性在Page_Load处始终为null

我试过了:

  • BatchType="<%# BatchType %>" -空
  • BatchType='<%# BatchType %>' -空
  • BatchType="<%= BatchType %>" -在这种情况下,我得到的是文字“ <%= BatchType%>”而不是null
  • `BatchType =“ <%$ Code:BatchType%>-得到了空

我很困惑,需要帮助。 有任何想法吗?

通过使用DataBind语法,我们可以获得结果。

BatchType='<%# BatchType %>'

但是,正如您指出的那样,此操作不会返回任何内容。 您需要包括告诉控件进行数据绑定的代码,以便可以评估BatchType

<% failedClaims.DataBind%>

它可以放在父用户控件内的任何位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM