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

时间:2019-03-20 07:31:49

标签: c# asp.net html5 webforms

我想在更新面板中使用更新面板和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>

如何解决此错误?

3 个答案:

答案 0 :(得分: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 :(得分:1)

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

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

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

答案 2 :(得分: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'