Repeater只将其FooterTemplate的一半渲染到我的流中

时间:2012-11-22 17:37:45

标签: asp.net vb.net

我的页面上有一个转发器,其中包含一个FooterTemplate,其中包含Literal我在页面的LoadComplete事件中写入。

FooterTemplate如下:

<FooterTemplate>
        <tr>
            <td colspan="3">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <b>Total:</b>
            </td>
            <td align="right">
                <asp:Literal runat="server" ID="ltrBasketTotal" />
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <b>Total inc. VAT:</b>
            </td>
            <td align="right">
                <asp:Literal runat="server" ID="ltrBasketTotalPlusVAT" />
            </td>
        </tr>
    </table>
</FooterTemplate>

我知道我的LoadComplete方法工作正常,因为我会在屏幕上显示总计和总增值税。在我的PlaceOrder方法中,我将转发器的内容呈现为流以包含在电子邮件中:

Using mStream As New System.IO.MemoryStream()

    Using writer As New System.IO.StreamWriter(mStream)

        Using rptSummaryContentWriter As HtmlTextWriter = New HtmlTextWriter(writer)

            rptSummary.RenderControl(rptSummaryContentWriter)

            Dim reader As New System.IO.StreamReader(mStream)
            reader.BaseStream.Position = 0

            customerOrderMail.Body = "Dear " & Session("displayname") & ",<br /><br />Thank you for your order through MyPortal, your reference for this order is " & newQuoteID.ToString() & ". Below is a summary of your order.<br /><br /><br />" & reader.ReadToEnd()

        End Using

    End Using

End Using

问题是我的电子邮件中包含表格中的所有内容,但总额加增值税的最后一行除外:

No total plus VAT row

有人知道为什么吗?

编辑:

检查我的电子邮件客户端中的来源,我发现我想要的行中的<tr><td>存在,但没有其他内容。这就像我过早地从流中读取,但我认为RenderControl会在将控制权返回给调用者之后完成?

1 个答案:

答案 0 :(得分:0)

原来我只需要在使用RenderControl之后刷新流。

rptSummary.RenderControl(rptSummaryContentWriter)

rptSummaryContentWriter.Flush()

Using reader As New System.IO.StreamReader(mStream)

    reader.BaseStream.Position = 0

    customerOrderMail.Body = "Dear " & Session("displayname") & ",<br /><br />Thank you for your order through MyPortal, your reference for this order is " & newQuoteID.ToString() & ". Below is a summary of your order.<br /><br /><br />" & reader.ReadToEnd()

End Using