Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem - any hidden field in Update Panel does not get updated

Tags:

asp.net

I am using C# for my programming.

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>

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

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.

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

Please suggest

Thanks.

like image 406
Manoj Singh Avatar asked Feb 08 '10 12:02

Manoj Singh


1 Answers

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.

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>
like image 163
KP. Avatar answered Oct 02 '22 12:10

KP.