I have a page with an ASP Place Holder wrapped in an Update Panel on it, I load a single User Control with another Place Holder wrapped in an Update Panel on it. I then load this newest Place Holder with multiple User Controls, each of which contains a Gridview wrapped in an Update Panel.
The data in each Gridview is based on the data in “previous” Gridviews, so when the user edits a row the changes cascade down the Gridviews, this is where my problem lies. After clicking the save button nothing visibly happens (all rows in the database are updated correctly) until I click another button anywhere on the page at which point all the changes are visibly updated in the Gridviews.
I’ve tried everything I can think of to fix this, no end of playing around with Update Panel options and positions, triggering an additional button click via JavaScript and any other solution I could find that seemed relevant, though none have got me any nearer to where I want to be.
If I’ve managed to convey my problems in such a way that anyone can understand I’d be grateful for insight, please ask questions if you feels I’ve not described something intelligibly.
Here are the three levels and page/user control/usercontrol:
Page:
<div id="divCustomerProductInput">
<asp:UpdatePanel ID="udpSalesOrders" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:PlaceHolder ID="plhCsCustomerproductInput" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
First User Control loaded into the placeholder above:
<asp:UpdatePanel ID="udpSalesOrders" runat="server" UpdateMode="Always" >
<ContentTemplate>
<asp:PlaceHolder runat="server" ID="plhProductionProcess"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
Second User Control loaded into the placeholder above multiple times:
<asp:UpdatePanel ID="udpPPI" runat="server" UpdateMode="Always">
<ContentTemplate>
<%-- MANUFACTURE--%>
<asp:GridView ID="gdvProductionProcessIngredients" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ingredient Description" ItemStyle-Width="21%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="txtIngredientDescription" runat="server" Text='<%# Eval("IngredientDescription") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ingredient Code" ItemStyle-Width="14%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="txtIngredientCode" runat="server" Text='<%# Eval("RmId") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="From" ItemStyle-Width="10%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="txtParentDepartment" runat="server" Text='<%# Eval("ParentDepartment") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity (%)" ItemStyle-Width="10%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:TextBox ID="txtQuantityKg" runat="server" Text='<%# Eval("OldestAncestorQuantityPercent") %>'
ForeColor="Black"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Input Cost / Kg (£)" ItemStyle-Width="13%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="lblCost" runat="server" Text='<%# Eval("InputCostKg") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Yield (%)" ItemStyle-Width="10%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:TextBox ID="txtYield" runat="server" Text='<%# Eval("Yield") %>' ForeColor="Black"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Output Cost / Kg (£)" ItemStyle-Width="14%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="lblCostPerKg" runat="server" Text='<%# Eval("OutputCostKg") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="6%" ControlStyle-Width="95%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnDeleteIngredient" CommandName="REMOVE" CommandArgument='<%# Eval("Id") %>'
CssClass="btn danger hover" runat="server" Text="Remove" /></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Ok, here’s the binding and updating code:
Dim myCsProductProductionProcessIngredients As New v2.Model.CsProductProductionProcessIngredientCollection
myCsProductProductionProcessIngredients.LoadByPPPId(_ProductProductionProcessId)
Me.gdvProductionProcessIngredients.DataSource = myCsProductProductionProcessIngredients
Me.gdvProductionProcessIngredients.DataBind()
Me.udpPPI.Update()
Thanks, Korv
I figured out why my Update Panels didn’t appear to be updating.
I was making an incorrect assumption about the page life-cycle and assuming that the event fired by the button click came before the page load.
I have now moved the Gridview population code to the Page_PreRender and everything is working as I intended.