Question

I'm trying to clean up an old ASP.NET app at work...

I've got a parent UserControl called FailedBatchPanel.ascx that is defined like:

<%@ 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>

The child control is FailedBatch.ascx and simply contains an asp:Repeater with databinding.

The Parent Control, FailedBatchPanel, is called as follows:

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

I want to pass the BatchType defined declaratively as above to the child control that is embedded in FailedBatchPanel.

As you can see from the example above, I've tried using the `<%$ Code: ... %> CodeExpressionBuilder as defined by InfinitiesLoop at http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx

In every case that I've tried, the BatchType public property defined in FailedBatch is always null at Page_Load

I've tried:

  • BatchType="<%# BatchType %>" -- got Null
  • BatchType='<%# BatchType %>' -- got Null
  • BatchType="<%= BatchType %>" -- in this case I got the literal "<%= BatchType %>" instead of null
  • `BatchType="<%$ Code: BatchType %> -- got Null

I'm stumped and need help. Any ideas?

Was it helpful?

Solution

By using the DataBind syntax we are able to get a result.

BatchType='<%# BatchType %>'

However, as you noted this returns nothing. You need to include code telling the control to databind so that BatchType will be evaluated:

<% failedClaims.DataBind%>

This may be placed anywhere within your parent usercontrol.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top