如何从直放站得到更新文本框的值

如何从直放站得到更新文本框的值

本文介绍了如何从直放站得到更新文本框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个转发控制如下所示。它有一个文本控制。当保存按钮被点击,我需要从文本框中的文字更新。我有以下的code;但它给了我,当我把文本框的文本旧值。

我们怎样才能获得更新的文字?

code背后

 保护无效Save_Click(对象发件人,EventArgs的发送)
    {        的foreach(在重新preports.Items的RepeaterItem项)
        {
            如果(item.ItemType == || ListItemType.Item == item.ItemType ListItemType.AlternatingItem)
            {                字符串updatedEmail =((文本框)item.Controls [5])文本。
                串originalEmail =((HiddenField)item.Controls [7])值。
            }
        }
    }

控制标记

 < D​​IV CLASS =repeaterTableBorder>
                < ASP:直放站ID =重新preports=服务器>
                    <&ItemTemplate中GT;
                        < D​​IV ID =repeaterIdentifier级=repeaterIdentifier>
                            < D​​IV CLASS =reportTitle>
                                &所述;%#评估和演示(REPORTNAME)+:%>
                                < ASP:HiddenField ID =hdnLastChangeTime=服务器值='<%#((日期时间)的eval(RecordSelectionTime))的ToString(MM / DD / YYYY HH:MM:SS.FFF TT )%>' />
                                < ASP:HiddenField ID =hdnReportID=服务器值='<%#的eval($的ReportType C $ C)%GT;' />
                            < / DIV>
                            < D​​IV CLASS =reportFrequency>
                                 <%#频率 - 周刊%GT;
                            < / DIV>
                        < / DIV>
                        < D​​IV CLASS =reportContent>
                            < D​​IV CLASS =repeaterLine>
                                < ASP:文本框ID =txtEmailRecipients=服务器级=文字编辑
                                    文字='<%#的eval(ExistingRecipients)%>'
                                    的TextMode =多行>< / ASP:文本框>
                                 < ASP:HiddenField ID =hdnOriginalRecipients=服务器值='<%#的eval(ExistingRecipients)%>' />
                            < / DIV>
                        < / DIV>                    < / ItemTemplate中>
                < / ASP:直放站>
            < / DIV>


解决方案

我认为你要绑定的转发到它的数据源还回发。你应该这样做,只有如果(!的IsPostBack)。否则,值将被覆盖。

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!的IsPostBack)
    {
        //绑定code在这里
    }
}

I have a repeater control as listed below. It has a textbox control. When a save button is clicked, I need to get the updated text from the textbox. I have the following code; but it gives me the old value when I take the textbox text.

How can we get the updated text?

Code Behind

    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;


            }
        }
    }

Control Markup

  <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>
解决方案

I assume that you are binding the Repeater to it's DataSource also on postbacks. You should do that only if(!IsPostBack). Otherwise the values will be overwritten.

protected void Page_Load(Object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        // databinding code here
    }
}

这篇关于如何从直放站得到更新文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:21