0
votes

There ASCX-controls that the program-loaded onto the page. In a Repeater control in which, depending on the conditions displayed a different set of COLUMNS and DataTable with a different set of columns.

So, on the ASPX-page, this construction work Good.

    <ItemTemplate>
        <tr class="objectrow" href="<%# GetCompleteViewObjectLink(Convert.ToInt32(Eval("ID_Object")))%>">
            <td align="center" class="c1">
                <%# Eval("ID_Object") %>
            </td>
            <% if (GetObjectTypeName() == "Sot")
               { %>
            <td align="center" class="c6">
                <%# Eval("SOTName") != DBNull.Value ? Eval("SOTName") : ""%>
            </td>
            <% } %>
............................

But in program-loaded to page ASCX-control I have an Exception:

Error: DataBinding: 'System.Data.DataRowView' does not contain a property named SOTName.

and another does not conform: in aspx-page my breakpoint on row

<% if (GetObjectTypeName() == "Sot")

was work off. But in ascx-control NOT.

Please, help! Why behaviour is so different? How to be?

2
strange situation: I set breakpoint to "if" condition and receive exception at this row <%# Eval("SOTName") != DBNull.Value ? Eval("SOTName") : ""%> then I press continue button & my cursor go to breakpoint setted by me 2 rows upper. Whatis this?! Lifecycle of aspx & ascx different??Pavel

2 Answers

0
votes

Check your data for actual rows, i.e. row count? I would bet your DataSource is null.

I don't think you're getting data when you think you should be.

The Page Load event of the user control will execute before the aspx Page Load. If you are getting some type of parameter for your query in the .ascx in the Page Load of the .aspx, you ought to grab that in the Page_Init of the .aspx.

0
votes

As TheGeekYouNeed points out, it's crucial to know when the DataSource of the Repeater is defined, as the control's events are processed before the page events.

You can add code like

<td>GetObjectTypeName='<%# GetObjectTypeName() %>'</td>

to find out whether the if() condition applies for your data.