我应该在哪里放置我的UpdatePanel

时间:2017-09-05 14:22:47

标签: c# html asp.net gridview

我的任务是将ASP Web应用程序更新到Visual Studio 2015.我有一个主页面,如下所示:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="HorizontalMenu.master.cs" Inherits="HomiLog2015.HorizontalMenu" %>
<%@ Register Src="~/Header and Footer/Footer.ascx" TagPrefix="uc1" TagName="Footer" %>
<%@ Register Src="~/Header and Footer/Header.ascx" TagPrefix="uc1" TagName="Header" %>
<%@ Register Src="~/Menu.ascx" TagPrefix="uc1" TagName="Menu" %>
<link href="App_Themes/Rockies/BaseStyles.css" rel="stylesheet" />

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>

<body id="Body1" runat="server">
<form runat="server" id="form1" method="post">
    <asp:ScriptManager ID="scriptManager1" runat="server" EnablePartialRendering="True" EnablePageMethods="True" EnableScriptGlobalization="True" EnableScriptLocalization="True">
        </asp:ScriptManager>
    <table border="0">
        <tr>
            <td class="pcT" colspan="2">
                <uc1:Header runat="server" ID="Header1" />
            </td>
            <td class="pcTR"></td>
        </tr>
        <tr>
            <td class="pcml"></td>
            <td class="MLMmc">
                <uc1:Menu runat="server" id="Menu1" />
            </td>
        </tr>
        <tr>
            <td class="pcL"></td>
            <td class="pcC">
                <asp:ContentPlaceHolder id="PageContent" runat="server"/>
            </td>
            <td class="pcR"></td>
        </tr>
        <tr>
            <td class="pcBL"></td>
            <td class="pcB">
                <uc1:Footer runat="server" ID="Footer1" />
            </td>
            <td class="pcBR"></td>
        </tr>
    </table>
</form>
</body>
</html>

我有一个带有GridView的ASP网页,需要编辑,删除和插入记录。我已经运行了编辑和删除功能,但是插入部分有问题。

当我尝试保存新记录时,所有数据字段都是空的。我知道C#代码正在读取行上的文本值,因为我有一个下拉列表和一个获取其值的行的复选框,但它是默认值,而不是我为插入选择的值。

非常确定这是一个回发问题,因为我注意到我的网页上没有UpdatePanel。我试图将gridview包装在UpdatePanel中,但是当我这样做时,我得到错误声明GridView不是已知元素。我尝试在div中包装gridview,然后在更新面板中包装div。但后来我得到的错误div不能嵌套在更新面板中。

所以我认为我需要在Master页面上包含更新面板,但是当我在那里移动它时无法编译它。我已经尝试将面板放在母版页上的不同位置。有人能指出我正确的方向吗?

我被要求提供更多代码,这是具有gridview的ASPX页面

<%@ Page Title="" Language="C#" MasterPageFile="~/HorizontalMenu.Master" 
AutoEventWireup="true" CodeBehind="EditMembers.aspx.cs" 
Inherits="HomiLog2015.EditMembers" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" 
TagPrefix="telerik" %>

<asp:Content ID="Content2" ContentPlaceHolderID="PageContent" 
runat="server">
<section id="searchHeader" class="Search">
    <p class="searchp">Members</p>
</section>
<section id="SearchArea" class="SearchBar">
    Search for:
    <br />
    <br />
    Last Name:
</section>
<section id="searchFooter" class="Search">
    <p>*</p>
</section>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" 
Skin="Default"></telerik:RadAjaxLoadingPanel>
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" />
<section id="grid" class="Grid-Container">
    <p style="text-align: Left;">
        <asp:Button ID="btnAdd" runat="Server" Text="Add New Record" 
OnClick="btnAdd_Click" /></p>

    <asp:GridView ID="MembersGridView" runat="server" EnableViewState="true"
        DataKeyNames="UserId"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true"
        AutoGenerateDeleteButton="false"
        OnRowDataBound="MembersGridView_RowDataBound"
        OnRowEditing="MembersGridView_RowEditing"
        OnRowCancelingEdit="MembersGridView_RowCancelingEdit"
        OnRowUpdating="MembersGridView_RowUpdating"
        OnRowUpdated="MembersGridView_RowUpdated"
        OnRowDeleting="MembersGridView_RowDeleting"
        OnRowCommand="MembersGridView_RowCommand"
        OnSorting="MembersGridView_Sorting"
        AllowPaging="true"
        AllowSorting="true"
        EmptyDataText="No Data Has Been Entered"
        HorizontalAlign="Left"
        ShowFooter="false"
        OnPageIndexChanging="MembersGridView_PageIndexChanging" 
BackColor="White" BorderColor="#999999" BorderStyle="Solid" 
BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton runat="server" ID="MembersDeleteButton"
                        CommandArgument='<%#Eval("username")%>'
                        OnClientClick="return confirm('Are you sure you want 
to delete this event?');"
                        OnCommand="DeleteMember" Text="Delete"
                        ImageUrl="../Images/Icon_delete.gif">
</asp:ImageButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Valid" ItemStyle-Width="10">
                <ItemTemplate>
                    <asp:CheckBox ID="chkActive" runat="server" Checked='<%# 
Eval("valid")%>' Enabled="false"></asp:CheckBox>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:CheckBox ID="chkActive" runat="server" Checked='<%# 
Eval("valid")%>'></asp:CheckBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:CheckBox ID="chkActive" runat="server" />
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="First Name" ItemStyle-
Width="100">
                <ItemTemplate>
                    <asp:Label ID="lblFirstName" runat="server" Text='<%# 
Eval("firstname")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtFirstName" runat="server" Text='<%# 
Eval("firstname")%>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtFirstName" Text="Hello" 
runat="server"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Name" ItemStyle-Width="100">
                <ItemTemplate>
                    <asp:Label ID="lblLastName" runat="server" Text='<%# 
Eval("Lastname")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtLastName" runat="server" Text='<%# 
Eval("Lastname")%>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtLastName" runat="server">
</asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="User Name" ItemStyle-Width="100">
                <ItemTemplate>
                    <asp:Label ID="lblUsertName" runat="server" Text='<%# 
Eval("username")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtUserName" runat="server" Text='<%# 
Eval("username")%>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtUserName" runat="server">
</asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Role" ItemStyle-Width="100">
                <ItemTemplate>
                    <asp:Label ID="lblRole" runat="server" Text='<%# 
Eval("role")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlRole" runat="server" 
DataTextField="Role1" DataValueField="RoleID"></asp:DropDownList>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:DropDownList ID="ddlRole" runat="server" 
DataTextField="Role1" DataValueField="RoleID"></asp:DropDownList>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Email" ItemStyle-Width="100">
                <ItemTemplate>
                    <asp:Label ID="lblEmail" runat="server" Text='<%# 
Eval("EmailAddress")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtemail" runat="server" Text='<%# 
Eval("EmailAddress")%>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                    <asp:Button ID="btnInsert" runat="Server" Text="Insert" 
CommandName="Insert" UseSubmitBehavior="False" />
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerSettings Mode="Numeric"
            Position="Bottom"
            PageButtonCount="10" />

        <AlternatingRowStyle BackColor="#CCCCCC" />
        <FooterStyle BackColor="#CCCCCC" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />

        <PagerStyle BackColor="#999999"
            Height="30px"
            VerticalAlign="Bottom"
            HorizontalAlign="center" ForeColor="Black" />

        <SelectedRowStyle BackColor="#000099" Font-Bold="True" 
ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#808080" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#383838" />

        <EmptyDataTemplate>
            <asp:CheckBox ID="chkActive" runat="server" Checked='<%# 
Eval("valid")%>' Enabled="false"></asp:CheckBox>
            <asp:Label ID="lblFirstName" runat="server" Text='<%# 
Eval("firstname")%>'></asp:Label>
            <asp:Label ID="lblLastName" runat="server" Text='<%# 
Eval("Lastname")%>'></asp:Label>
            <asp:Label ID="lblUsertName" runat="server" Text='<%# 
Eval("username")%>'></asp:Label>
            <asp:DropDownList ID="ddlRole" runat="server" 
DataTextField="Role1" DataValueField="RoleID"></asp:DropDownList>
            <asp:Label ID="lblEmail" runat="server" Text='<%# 
Eval("EmailAddress")%>'></asp:Label>
        </EmptyDataTemplate>


    </asp:GridView>

</section>

</asp:Content>

我已尝试将更新面板放在此页面的不同位置,但无法编译。

1 个答案:

答案 0 :(得分:0)

母版页用于造型。在这种情况下你不应该碰它们。

MasterPageFile 属性添加到包含GridView的.aspx标记文件中的 Page 元素。

 <%@ Page MasterPageFile="~/YOUR_MASTER_PAGE_FILE" ... %>

请注意母版页中 asp:ContentPlaceHolder 的ID。

<asp:ContentPlaceHolder id="PageContent" runat="server"/>

将新的.aspx页面的内容包含在 asp:Content 元素中,该元素的属性 asp:ContentPlaceHolderID 等于 asp的ID:主页文件中的ContentPlaceHolder 元素。

<asp:Content ID="mainPlaceHolder" ContentPlaceHolderID="PageContent" runat="server">

Here is an example for inserting records using a GridView

请为GridView发布相关的标记和后端代码并插入逻辑。根据提供的信息,我无法提供更多帮助。