2

我有一个repeater如下所列的控件。它有一个textbox控制。单击a 时save button,我需要从文本框中获取更新的文本。我有以下代码;但是当我获取文本框文本时,它给了我旧值。

我们如何获得更新的文本?

代码背后

    protected void Save_Click(object sender, EventArgs e)
    {

        foreach (RepeaterItem item in repReports.Items )
        {
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem )
            {

                string updatedEmail = ((TextBox)item.Controls[5]).Text;
                string originalEmail = ((HiddenField)item.Controls[7]).Value;


            }
        }
    }

控制标记

  <div class="repeaterTableBorder">
                <asp:Repeater ID="repReports" runat="server">
                    <ItemTemplate>
                        <div id="repeaterIdentifier" class="repeaterIdentifier">
                            <div class="reportTitle">
                                <%# Eval("ReportName") + ":"%>
                                <asp:HiddenField ID="hdnLastChangeTime" runat="server" Value= '<%# ((DateTime)Eval("RecordSelectionTime")).ToString("MM/dd/yyyy hh:mm:ss.fff tt")%>' />
                                <asp:HiddenField ID="hdnReportID" runat="server" Value='<%# Eval("ReportTypeCode")%>' />
                            </div>
                            <div class="reportFrequency">
                                 <%# " Frequency - Weekly" %> 
                            </div>
                        </div>
                        <div class="reportContent">
                            <div class="repeaterLine">
                                <asp:TextBox ID="txtEmailRecipients" runat="server" class="textEdit" 
                                    Text='<%# Eval("ExistingRecipients") %>'
                                    TextMode="MultiLine"></asp:TextBox>
                                 <asp:HiddenField ID="hdnOriginalRecipients" runat="server" Value='<%# Eval("ExistingRecipients")%>' />
                            </div>
                        </div>

                    </ItemTemplate>
                </asp:Repeater>
            </div>
4

1 回答 1

9

我假设您将其绑定Repeater到它DataSource也在回发中。你应该只这样做if(!IsPostBack)。否则这些值将被覆盖。

protected void Page_Load(Object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        // databinding code here
    }
}
于 2012-11-30T15:23:59.277 回答