问题 - 更新面板中的隐藏字段没有更新 [英] Problem - any hidden field in Update Panel does not get updated

查看:89
本文介绍了问题 - 更新面板中的隐藏字段没有更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#我的节目。

我现在面临的问题,那个时候它是在更新面板隐藏我的变量值不被更新。请参考下面code为ASPX:

I am facing issue, that my hidden variable value is not being updated when it is in update panel. Please see below code for 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>

和下方则是code,其中我试图更新我的CS code中的隐藏字段中的一个。

and below is the code where I am trying to update one of the hidden field with my CS code.

有趣的是,当我试图调试它显示所有的值,但是当我看到它f。关于网页源代码它不给任何值。

Interesting, when I am trying to debug its showing all the values, however when I see it f on page source it doesn't give any value.

下面是我的aspx.cs code:

Here is my aspx.cs code:

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();
        }            
    }
}

请提示

感谢。

推荐答案

您隐藏的输入字段不更新面板控制范围之内。任何异步往返服务器将只会使的UpdatePanel 本身的控制,以更新的用户界面,因此即使code-背后运行,并更新隐藏场,在前端,他们保持不变,因为他们坐在面板外。

Your hidden input fields are not within the update panel control. Any asynchronous round trips to the server will cause only those controls within the UpdatePanel itself to update on the UI, so even though the code-behind runs and updates the hidden fields, on the front end they stay the same because they sit outside the panel.

尝试中移动的隐藏字段中的&LT;&的ContentTemplate GT; 标签:

Try moving the hidden fields within the <ContentTemplate> tag:

<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>

这篇关于问题 - 更新面板中的隐藏字段没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆