简体   繁体   English

我应该在哪里放置UpdatePanel

[英]Where should I put my UpdatePanel

I have been tasked with updating an ASP web Application to Visual Studio 2015. I have a Master page that looks like this: 我的任务是将ASP Web应用程序更新为Visual Studio2015。我有一个母版页,如下所示:

<%@ 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>

I Have an ASP web page with a GridView and need to Edit, Delete, and Insert records. 我有一个带有GridView的ASP网页,需要编辑,删除和插入记录。 I have gotten the edit and delete functions running but am having a problem with the Insert portion. 我已经运行了编辑和删除功能,但是插入部分有问题。

When I attempt to save the new record all of the data fields are empty. 当我尝试保存新记录时,所有数据字段均为空。 I know the C# code is reading the text values on the row because I have a dropdown and a checkbox on the rows that are getting their values, but it is the default values and not the ones I selected for the insert. 我知道C#代码正在读取行上的文本值,因为我在要获取其值的行上有一个下拉列表和一个复选框,但这是默认值,而不是我为插入选择的值。

Pretty sure it is a post back problem since I have noticed I don't have an UpdatePanel on my web page. 可以肯定的是,这是一个回发问题,因为我注意到我的网页上没有UpdatePanel。 I have tried to wrap the gridview within an UpdatePanel but when I do that I get the error stating GridView is not a known element. 我试图将Gridview包装在UpdatePanel中,但是当我这样做时,出现错误,说明GridView不是已知元素。 I have tried wrapping the gridview in a Div and then wrapping the div in the update panel. 我尝试将gridview封装在Div中,然后将div包装在更新面板中。 But then I get the Error div cannot be nested in the update panel. 但是,然后我得到Error div无法嵌套在更新面板中。

So I think I need to include the update panel on the Master page but cannot get it to compile when I move it over there. 因此,我认为我需要在“母版”页面上包含更新面板,但是当我将其移到那里时无法对其进行编译。 I have tried putting the panel in various location on the Master Page. 我尝试将面板放在母版页的各个位置。 Can someone point me in the right direction on this? 有人可以为此指出正确的方向吗?

I have been asked to provide more code here is the ASPX page that has the gridview 我被要求提供更多代码,这里是具有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>

I have tried putting the update panel in various locations on this page but it will not compile. 我尝试将更新面板放在此页面上的不同位置,但无法编译。

Master pages are for styling. 母版页用于样式设置。 You should not be touching them in this case. 在这种情况下,请勿触摸它们。

Add the MasterPageFile attribute to the Page element in your .aspx markup file that contains your GridView. MasterPageFile属性添加到包含GridView的.aspx标记文件中的Page元素中。

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

Note the id of the asp:ContentPlaceHolder in your Master page. 请注意母版页中asp:ContentPlaceHolder的ID。

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

Wrap the content of your new .aspx page in a asp:Content element which has an attribute asp:ContentPlaceHolderID equal to the ID of the asp:ContentPlaceHolder element in your master page file. 将新.aspx页的内容包装在asp:Content元素中,该元素的属性asp:ContentPlaceHolderID等于母版页文件中asp:ContentPlaceHolder元素的ID。

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

Here is an example for inserting records using a GridView 这是使用GridView插入记录的示例

Please post the relevant markup and back-end code for you GridView and insert logic. 请为您发布GridView的相关标记和后端代码,并插入逻辑。 I can't offer any more assistance based on the information provided. 根据所提供的信息,我无法提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM