locked
No updatemode with detailview in updatepanel RRS feed

  • Question

  • User-277541937 posted

    Hello,

     

    I have a detail view in a updatepanel. The trigger is a treeview. When i want to update the data a can't see anything.

    *.aspx

    <%@ Page Title="" Language="C#" MasterPageFile="~/AdminSite.Master" AutoEventWireup="true" CodeBehind="WetTekstEdit.aspx.cs" Inherits="Bouwgegevens.nl.Sitemanager.WetTekstEdit" %>
    <%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="cphHeaderContent" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="cphMainContent" runat="server">
        <h1>Wettekst Aanpassen</h1>
        <div id="dvWetAanpassen">
            <asp:DropDownList ID="ddlWettekst" runat="server" AppendDataBoundItems="true" AutoPostBack="true" DataSourceID="edsDdlWetTekst" 
                DataTextField="TitelWet" DataValueField="WetID">
                <asp:ListItem Text="Kies een Wet" Value="0" />
            </asp:DropDownList><br /><br />
            <asp:EntityDataSource runat="server" ID="edsDdlWetTekst" DefaultContainerName="DBBouwgegevensEntities"
                ConnectionString="name=DBBouwgegevensEntities" EnableFlattening="False" EntitySetName="tbl_Wetten"
                Select="it.[WetID], it.[TitelWet]" EntityTypeFilter="tbl_Wetten">
            </asp:EntityDataSource>
             <table class="tblWetTekst">
            <tr>
                <td class="tdWetMenuHeader">
                    <asp:DetailsView ID="dtvWet" runat="server" CssClass="dtvWetTekst"
                        AutoGenerateRows="False" RowStyle-VerticalAlign="NotSet" GridLines="None"
                        BorderWidth="0px" BorderStyle="None" DataSourceID="edsWet" >
                        <Fields>
                            <asp:TemplateField ShowHeader="False"  SortExpression="TitelWet">
                                <ItemTemplate>
                                    <h3>
                                        <asp:Label runat="server" Text='<%# Bind("TitelWet") %>' ID="Label1"></asp:Label></h3>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Fields>
                    </asp:DetailsView>
                    <asp:EntityDataSource runat="server" ID="edsWet" DefaultContainerName="DBBouwgegevensEntities"
                        ConnectionString="name=DBBouwgegevensEntities" EnableFlattening="False" EntitySetName="tbl_Wetten"
                        EntityTypeFilter="tbl_Wetten" Select="it.[WetID], it.[TitelWet]" Where="it.[WetID] = @WetID">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="ddlWettekst" Name="WetID" Type="Int32" PropertyName="SelectedValue" />
                            <%--<asp:QueryStringParameter QueryStringField="WetID" Name="WetID" Type="Int32" />--%>
                        </SelectParameters>
                    </asp:EntityDataSource>
                </td>
                <td class="tdSpace"></td>
                <td class="tdWetTekstHeader">
                    <asp:DetailsView ID="DetailsView1" runat="server" CssClass="dtvWetTekst"
                        AutoGenerateRows="False" RowStyle-VerticalAlign="NotSet" GridLines="None"
                        BorderWidth="0px" BorderStyle="None" DataSourceID="edsWetTitel">
                        <Fields>
                            <asp:BoundField DataField="Wet_Titel" ShowHeader="false" ReadOnly="True" SortExpression="Wet_Titel"></asp:BoundField>
                        </Fields>
                    </asp:DetailsView>
                    <asp:EntityDataSource runat="server" ID="edsWetTitel" DefaultContainerName="DBBouwgegevensEntities" 
                        ConnectionString="name=DBBouwgegevensEntities" EnableFlattening="False" EntitySetName="tbl_WetTeksten" 
                        Select="it.[WetTekstID], it.[Wet_Titel]" Where="it.[WetTekstID]=@WetTekstID">
                        <WhereParameters>
                            <asp:ControlParameter ControlID="trvWetTekst" Name="WetTekstID" PropertyName="SelectedValue" Type="Int32" />
                        </WhereParameters>
                    </asp:EntityDataSource>
                </td>
            </tr>
            <tr>
                <td class="tdWetMenuContent">
                    <asp:TreeView ID="trvWetTekst" runat="server" ClientIDMode="Static"
                        ExpandDepth="0" ForeColor="#6A8486" NodeWrap="True" Font-Size="9pt"
                        SelectedNodeStyle-ForeColor="#FF6600" ShowExpandCollapse="true" Width="275"
                        NodeStyle-VerticalPadding="1px" NodeStyle-NodeSpacing="3px" NodeStyle-HorizontalPadding="3px"
                        ParentNodeStyle-HorizontalPadding="3px">
                    </asp:TreeView>
                </td>
                <td class="tdSpace">
                </td>
                <td class="tdWetTekstContent">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:DetailsView ID="DetailsView2" runat="server" Width="100%" AutoGenerateRows="False"
                                DataKeyNames="WetTekstID" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="edsWetDetailsTekst">
                                <AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
    
                                <CommandRowStyle BackColor="#E2DED6" Font-Bold="True"></CommandRowStyle>
    
                                <EditRowStyle BackColor="#999999" Width="700px"></EditRowStyle>
                                <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="150px"></FieldHeaderStyle>
                                <Fields>
                                    <asp:TemplateField HeaderText="WetOmschrijving" SortExpression="WetOmschrijving" ShowHeader="False">
                                        <EditItemTemplate>
                                            <%--<CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor/" runat="server" Text='<%# Bind("Wet_Omschrijving") %>' Width="844px" Height="300px"></CKEditor:CKEditorControl>--%>
                                            <asp:TextBox runat="server" Text='<%# Bind("Wet_Omschrijving") %>' ID="TextBox3" Width="844px" TextMode="MultiLine"></asp:TextBox>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <asp:TextBox runat="server" Text='<%# Bind("Wet_Omschrijving") %>' ID="TextBox3" Width="844px" TextMode="MultiLine"></asp:TextBox>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label runat="server" Text='<%# Bind("Wet_Omschrijving") %>' ID="Label3"></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowInsertButton="True" ShowEditButton="True" ShowDeleteButton="True"></asp:CommandField>
                                </Fields>
                                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
    
                                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Width="150px"></HeaderStyle>
    
                                <PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>
    
                                <RowStyle BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
                            </asp:DetailsView>
                            <asp:EntityDataSource runat="server" ID="edsWetDetailsTekst" DefaultContainerName="DBBouwgegevensEntities" 
                                ConnectionString="name=DBBouwgegevensEntities" EnableFlattening="False" EnableUpdate="True" 
                                EntitySetName="tbl_WetTeksten" Where="it.[WetTekstID] = @WetTekstID">
                                <WhereParameters>
                                    <asp:ControlParameter ControlID="trvWetTekst" Name="WetTekstID" PropertyName="SelectedValue" Type="Int32" />
                                </WhereParameters>
    
                            </asp:EntityDataSource>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="trvWetTekst" />
                        </Triggers>
                    </asp:UpdatePanel>
                </td>
            </tr>
        </table>
        </div>
    </asp:Content>
    

    *.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Bouwgegevens.nl.Sitemanager
    {
        public partial class WetTekstEdit : System.Web.UI.Page
        {
            //protected void Page_Init(object sender, EventArgs e)
            //{
            //    PopulateMenu();
            //}
            
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!ScriptManager.GetCurrent(this).IsInAsyncPostBack)
                {
                    
                    trvWetTekst.Nodes.Clear();
    PopulateMenu();
                }
                else
                {
                    //code when it is an async postback
    
                    trvWetTekst.Nodes.Clear();
                    PopulateMenu();
                
                }
            }
    
            private void PopulateMenu()
            {
                
    
                List<tbl_WetTeksten> allMenu = new List<tbl_WetTeksten>();
    
                using (DBBouwgegevensEntities dc = new DBBouwgegevensEntities())
                {
                    allMenu = dc.tbl_WetTeksten.ToList();
                }
                // Call function here for bind treeview
                CreateTreeView(allMenu, 0, null);
                
            }
    
            private void CreateTreeView(List<tbl_WetTeksten> source, int parentID, TreeNode parentNode)
            {
                int wetId = Convert.ToInt32(ddlWettekst.SelectedValue);
    
                List<tbl_WetTeksten> newSource = source.Where(a => a.ParentID.Equals(parentID) && a.WetID.Equals(wetId)).ToList();
    
                foreach (var i in newSource)
                {
                    TreeNode newnode = new TreeNode("<b>" + i.Wet_Code + "</b>" + " " + i.Wet_Titel, i.WetTekstID.ToString());
                    if (parentNode == null)
                    {
                        trvWetTekst.Nodes.Add(newnode);
                    }
                    else
                    {
                        parentNode.ChildNodes.Add(newnode);
                    }
                    CreateTreeView(source, i.WetTekstID, newnode);
                }
            }
        }
    }

    How do I get the updatemode working.

     

    Kind regards Mark

     

    Saturday, March 15, 2014 3:21 PM

Answers

  • User-277541937 posted

    Hello, This solution did not work.

    This was the solution.

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!ScriptManager.GetCurrent(this).IsInAsyncPostBack)
                {
                    
                    trvWetTekst.Nodes.Clear();
                    PopulateMenu();
                }
                else
                {
                    //code when it is an async postback
    
                    //trvWetTekst.Nodes.Clear();
                    PopulateMenu();
                
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 16, 2014 3:48 PM

All replies

  • User1208776063 posted

    Mark Kooijman

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!ScriptManager.GetCurrent(this).IsInAsyncPostBack)
                {
                    
                    trvWetTekst.Nodes.Clear();
    PopulateMenu();
                }
                else
                {
                    //code when it is an async postback
    
                    trvWetTekst.Nodes.Clear();
                    PopulateMenu();
                
                }
            }

    You don't need to clear and recreate treeview items on page postbacks.  Control state will be retained across partial page updates and full page postbacks as well. If you wrap that treeview loading logic within if(!IsPostBack), your code should work fine. As you are clearing the items, you will lose the selection as well. That's why DetailsView is not being refreshed no matter what you select in the treeview

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateMenu();
        }
    }
    

    Also, you don't need to clear TreeView items across page postbacks. Try above approach and see if it works.

    Sunday, March 16, 2014 4:33 AM
  • User-277541937 posted

    Hello, This solution did not work.

    This was the solution.

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!ScriptManager.GetCurrent(this).IsInAsyncPostBack)
                {
                    
                    trvWetTekst.Nodes.Clear();
                    PopulateMenu();
                }
                else
                {
                    //code when it is an async postback
    
                    //trvWetTekst.Nodes.Clear();
                    PopulateMenu();
                
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 16, 2014 3:48 PM