I have GridView
which has a FooterRow where I am using labels to display Totals of each column.
I am accessing GridView
in JQuery and the totals are calculated successfully using JQuery and displayed in FooterRow
of each column of GridView.
<asp:TemplateField HeaderText="Age">
<ItemTemplate>
<asp:Label ID="lblAge" Text='<%# Eval("Age") %>' runat="server"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lbltotalAge" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
But when I click submit button and try to access these values in code behind inside button click event , all the Total values are not shown and remain as default Zero value.
string totalAge = ((Label)GrdV.FooterRow.FindControl("lbltotalAge")).Text; // always 0
To overcome this I have used HiddenField
controls outside the GridView as suggested in this previous POST.
After calculating Total values in Jquery function I copy these values to respective HiddenFields
and successfully getting the values in codebehind.
My question is why is this so ? Whats special about hiddenfields ?