如何解决:“元素div不能嵌套在元素'updatepanel'中”

问题描述 投票:0回答:3

我想在更新面板中使用更新面板和div,但我得到错误:元素div不能嵌套在元素'updatepanel'中。这是我的代码:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <div style="overflow:scroll">
    <asp:GridView ID="GridViewHome" runat="server" Width="100%"  AutoGenerateColumns="false" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridViewHome_PageIndexChanging" PageSize="30" ShowFooter="True">

               <Columns>

                   <asp:TemplateField>
                    <HeaderTemplate>Options</HeaderTemplate>
                    <ItemTemplate>
                        <div style="width:100%"> <asp:HyperLink ID="HyperLink1"  NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("Request number")+"&DEPT ID=" +Eval("DEPT ID")+"&Test Id=" +Eval("Test Id")+"&Culture=" +Eval("Culture")%>' runat="server">Print Result</asp:HyperLink></div>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <HeaderTemplate>Patient MRN#</HeaderTemplate>
                    <ItemTemplate>
                      <div style="width:100%">  <asp:Label ID="lblpatient" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label></div>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Patient Name</HeaderTemplate>
                    <ItemTemplate>
                       <div style="width:100%"> <asp:Label ID="lblname" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label></div> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Order Number</HeaderTemplate>
                    <ItemTemplate>
                       <div style="width:100%"> <asp:Label ID="lblorder" runat="server" Text='<%# Eval("Request number") %>'></asp:Label></div>
                    </ItemTemplate>
                </asp:TemplateField>


            </Columns>


        </asp:GridView>
        </div>

        </asp:UpdatePanel>

如何解决这个错误?

c# asp.net html5 webforms
3个回答
1
投票

updatepanel可以包含ContentTemplate,因此像这样添加ContentTemplate:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <div style="overflow:scroll">
    <asp:GridView ID="GridViewHome" runat="server" Width="100%"  AutoGenerateColumns="false" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridViewHome_PageIndexChanging" PageSize="30" ShowFooter="True">

               <Columns>

                   <asp:TemplateField>
                    <HeaderTemplate>Options</HeaderTemplate>
                    <ItemTemplate>
                        <div style="width:100%"> <asp:HyperLink ID="HyperLink1"  NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("Request number")+"&DEPT ID=" +Eval("DEPT ID")+"&Test Id=" +Eval("Test Id")+"&Culture=" +Eval("Culture")%>' runat="server">Print Result</asp:HyperLink></div>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <HeaderTemplate>Patient MRN#</HeaderTemplate>
                    <ItemTemplate>
                      <div style="width:100%">  <asp:Label ID="lblpatient" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label></div>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Patient Name</HeaderTemplate>
                    <ItemTemplate>
                       <div style="width:100%"> <asp:Label ID="lblname" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label></div> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Order Number</HeaderTemplate>
                    <ItemTemplate>
                       <div style="width:100%"> <asp:Label ID="lblorder" runat="server" Text='<%# Eval("Request number") %>'></asp:Label></div>
                    </ItemTemplate>
                </asp:TemplateField>


            </Columns>


        </asp:GridView>
        </div>
        </ContentTemplate>
        </asp:UpdatePanel>

1
投票

在ContentTemplate标记内插入div,如下所示:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div style="overflow:scroll">
            //stuff

        </div>
    </ContentTemplate>
</asp:UpdatePanel>

1
投票

您可以在<ContentTemplate>中添加<asp:UpdatePanel>部分来保存div元素,因为UpdatePanel只能有ContentTemplate部分:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div style="overflow:scroll">
        <asp:GridView ID="GridViewHome" runat="server" Width="100%"  AutoGenerateColumns="false" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridViewHome_PageIndexChanging" PageSize="30" ShowFooter="True">
            <%-- gridview contents --%>
        </asp:GridView>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

参考:

validation (xhtml5): the element 'div' cannot be nested within the element 'updatepanel'

© www.soinside.com 2019 - 2024. All rights reserved.