问题 - 更新面板中的任何隐藏字段都不会更新

时间:2010-02-08 12:18:43

标签: asp.net

我正在使用C#进行编程。

我遇到问题,我的隐藏变量值在更新面板中时没有更新。请参阅下面的aspx代码:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick">
        </asp:Timer>
        <input type="hidden" runat="server" id="hidCurrentDate" value="" />
        <input type="hidden" runat="server" id="hidTripIds" value="" />
        <input type="hidden" runat="server" id="hidTripDetails" value="" />

<asp:UpdateProgress ID="uprogTrips" runat="server">
            <ProgressTemplate>
                <span style="display: block; text-align: center">
                    <p style="font-family: Verdana; font-size: larger; font-weight: bold;">
                        <img src="../../Images/ajax-loader.gif" alt="Processing..." /><br />
                        <br />
                        Processing...</p>
                </span>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:UpdatePanel ID="upTripsGrid" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:GridView ID="gvAllTrips" runat="server" OnRowDataBound="gvAllTrips_RowDataBound"
                    OnPageIndexChanging="gvAllTrips_PageIndexChanging" AllowPaging="true" AutoGenerateColumns="false">
                    <PagerSettings Mode="NumericFirstLast" PageButtonCount="35" Position="TopAndBottom" />
                    <PagerStyle CssClass="GridPager" />                    
                </asp:GridView>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                <asp:AsyncPostBackTrigger ControlID="ddSortBy" EventName="SelectedIndexChanged" />
                <asp:AsyncPostBackTrigger ControlID="ddFilterBy" EventName="SelectedIndexChanged" />
                <asp:AsyncPostBackTrigger ControlID="cbPageOptions" EventName="CheckedChanged" />
            </Triggers>
</asp:UpdatePanel>

及以下是我尝试使用我的CS代码更新其中一个隐藏字段的代码。

有趣的是,当我尝试调试它显示所有值时,但是当我在页面源上看到它时它没有给出任何值。

这是我的aspx.cs代码:

protected void Timer1_Tick(object sender, EventArgs e)
{
    DataTable dtTrips = null;
    WEX.Prototype.Data.TripDA tripDA = new WEX.Prototype.Data.TripDA();
    string tID = hidTripIds.Value;
    string[] tripIDs = new string[1000];
    tripIDs = tID.Split(',');


    foreach (string tripID in tripIDs)
    {
        TripSummaryBO tripSummaryBO = tripDA.getTripSummary(Convert.ToInt32(tripID));
        if (tripSummaryBO.tripLastEditedOnDate > Convert.ToDateTime(hidCurrentDate.Value))
        {

            WEX.Prototype.Service.WSProxies WSProxies = new WEX.Prototype.Service.WSProxies();
            dtTrips = WSProxies.Build();
            Session["AllTrips"] = dtTrips;
            dtTrips = (DataTable)Session["AllTrips"];
            if (dtTrips != null)
            {
                if (cnt==0)
                {
                    hidTripDetails.Value = ("Trip name-" + tripSummaryBO.tripName + " was modified by user " + tripSummaryBO.tripLastEditedBy);
                }
                else
                {
                    hidTripDetails.Value = hidTripDetails.Value + " <br/> " + ("Trip name-" + tripSummaryBO.tripName + " was modified by user " + tripSummaryBO.tripLastEditedBy);
                }
                BuildGridViewControl(dtTrips);
                cnt = cnt + 1;
            }
        }
        else
        {
            //upTripsGrid.Triggers.Clear();
            PageInit();
        }            
    }
}

请建议

感谢。

1 个答案:

答案 0 :(得分:18)

您的隐藏输入字段不在更新面板控件中。任何到服务器的异步往返都只会导致UpdatePanel本身内的那些控件在UI上更新,所以即使代码隐藏运行并更新隐藏字段,在前端它们保持不变,因为它们坐在小组外面。

尝试移动<ContentTemplate>标记中的隐藏字段:

<asp:UpdatePanel ID="upTripsGrid" runat="server" UpdateMode="Always">
    <ContentTemplate>
        <input type="hidden" runat="server" id="hidCurrentDate" value="" />
        <input type="hidden" runat="server" id="hidTripIds" value="" />
        <input type="hidden" runat="server" id="hidTripDetails" value="" />
        ....
    </ContentTemplate>
</asp:UpdatePanel>