更新面板内的转发器,每行都有更新 LinkBut​​ton 在 LinkBut​​ton 单击页面 Post 返回

Repeater Inside Update Panel With Update LinkButton On Each Row Taking Page Post back on LinkButton Click

我在 Page_Load 上让 Repeater 与数据库绑定。 Repeater 放置在UpdatePanel 之间。每行都有链接按钮。当点击 linkbutton 页面去回传。如果中继器保留在 UpdatePanel 下,为什么中继器页面会回发?

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                         
                        <div class="row">
                             

                        <asp:Repeater ID="repeater1" runat="server">
                            <HeaderTemplate>
                                <table class="table table-bordered">
                                    <thead class="thead-light">
                                        <tr>
                                            <th>Post</th>
                                            <th>Sanctioned</th>
                                            <th>Filled</th>
                                            <%--<th>Surplus/Deployed</th>--%>
                                            <th>Vacant</th>
                                            <th>Paydrawal Orders</th>
                                            <th>Supernumerary Post</th>
                                            <th>Deployed Working Without Post</th>
                                            <th>Inposition Only</th>
                                            <th>Non-Teaching<br />In-position Samagra</th>
                                            <th>Remarks</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>
                                
                                <%# Eval("sanctioned").ToString() == "0" ? "<tr style='display:none;'>" : "<tr>" %>                                  
                                    <td><asp:Label ID="LabelPostname" runat="server" Text='<%# Server.HtmlEncode(Eval("postname").ToString()) %>' Font-Bold="true"></asp:Label>
                                        <asp:Label ID="LabelPostid" runat="server" Text='<%# Server.HtmlEncode(Eval("post_id").ToString()) %>' Visible="false"></asp:Label></td>
                                    <td><%# Server.HtmlEncode(Eval("sanctioned").ToString()) %></td>
                                    <td><%# Server.HtmlEncode(Eval("inposition").ToString()) %></td>
                                    <%--<td><%# Server.HtmlEncode(Eval("surplusdeployed").ToString()) %></td>--%>
                                    <td><%# Server.HtmlEncode(Eval("vacant").ToString()) %></td>
                                    <td><asp:TextBox ID="TextBoxPaydrawalOrders" runat="server" Text='<%# Server.HtmlEncode(Eval("PaydrawalOrders").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                    <td><asp:TextBox ID="TextBoxSupernumeraryPost" runat="server" Text='<%# Server.HtmlEncode(Eval("SupernumeraryPost").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                    <td><asp:TextBox ID="TextBoxDeployedWorkingwithoutpost" runat="server" Text='<%# Server.HtmlEncode(Eval("DeployedWorkingWithoutPost").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                    <td><asp:TextBox ID="TextBoxInpositionOnly" runat="server" Text='<%# Server.HtmlEncode(Eval("InpositionOnly").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                    <td><asp:TextBox ID="TextBoxNonTeachingInpositionSamagra" runat="server" Text='<%# Server.HtmlEncode(Eval("NonTeachingInpositionSamagra").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                    <td><asp:TextBox ID="TextBoxRemarks" runat="server" Text='<%# Server.HtmlEncode(Eval("Remarks").ToString()) %>' CssClass="form-control" MaxLength="300" placeholder="Max 300 Chars" Width="120px" TextMode="MultiLine" Height="50px" style="font-size:12px;"></asp:TextBox></td>
                                    
                                    <td><asp:LinkButton ID="LinkButtonUpdate" OnClick="LinkButtonUpdate_Click" runat="server" CssClass="btn btn-sm btn-primary">Save</asp:LinkButton></td>                                    
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </tbody>
                               </table>
                            </FooterTemplate>
                        </asp:Repeater>
                            
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>

HTML

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormProject.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        th {
            width: 140px;
        }
    </style>
</head>
<body>
    <div>
        <form runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <div class="row">
                        <asp:Repeater ID="repeater1" runat="server">
                            <HeaderTemplate>
                                <table class="table table-bordered">
                                    <thead class="thead-light">
                                        <tr>
                                            <th>Post</th>
                                            <th>Sanctioned</th>
                                            <th>Filled</th>
                                            <th>Vacant</th>
                                            <th>Paydrawal Orders</th>
                                            <th>Supernumerary Post</th>
                                            <th>Deployed Working Without Post</th>
                                            <th>Inposition Only</th>
                                            <th>Non-Teaching<br />
                                                In-position Samagra</th>
                                            <th>Remarks</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>

                                <%# Eval("sanctioned").ToString() == "0" ? "<tr style='display:none;'>" : "<tr>" %>
                                <td>
                                    <asp:Label ID="LabelPostname" runat="server" Text='<%# Server.HtmlEncode(Eval("postname").ToString()) %>' Font-Bold="true"></asp:Label>
                                    <asp:Label ID="LabelPostid" runat="server" Text='<%# Server.HtmlEncode(Eval("post_id").ToString()) %>' Visible="false"></asp:Label></td>
                                <td><%# Server.HtmlEncode(Eval("sanctioned").ToString()) %></td>
                                <td><%# Server.HtmlEncode(Eval("inposition").ToString()) %></td>
                                <td><%# Server.HtmlEncode(Eval("vacant").ToString()) %></td>
                                <td>
                                    <asp:TextBox ID="TextBoxPaydrawalOrders" runat="server" Text='<%# Server.HtmlEncode(Eval("PaydrawalOrders").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                <td>
                                    <asp:TextBox ID="TextBoxSupernumeraryPost" runat="server" Text='<%# Server.HtmlEncode(Eval("SupernumeraryPost").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                <td>
                                    <asp:TextBox ID="TextBoxDeployedWorkingwithoutpost" runat="server" Text='<%# Server.HtmlEncode(Eval("DeployedWorkingWithoutPost").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                <td>
                                    <asp:TextBox ID="TextBoxInpositionOnly" runat="server" Text='<%# Server.HtmlEncode(Eval("InpositionOnly").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                <td>
                                    <asp:TextBox ID="TextBoxNonTeachingInpositionSamagra" runat="server" Text='<%# Server.HtmlEncode(Eval("NonTeachingInpositionSamagra").ToString()) %>' CssClass="form-control" MaxLength="3"></asp:TextBox></td>
                                <td>
                                    <asp:TextBox ID="TextBoxRemarks" runat="server" Text='<%# Server.HtmlEncode(Eval("Remarks").ToString()) %>' CssClass="form-control" MaxLength="300" placeholder="Max 300 Chars" Width="120px" TextMode="MultiLine" Height="50px" Style="font-size: 12px;"></asp:TextBox></td>

                                <td>
                                    <asp:LinkButton ID="LinkButtonUpdate" OnClick="LinkButtonUpdate_Click" runat="server" CssClass="btn btn-sm btn-primary">Save</asp:LinkButton></td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </tbody>
                               </table>
                            </FooterTemplate>
                        </asp:Repeater>

                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>
    </div>
</body>
</html>

代码

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

    private void GetData()
    {
        try
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("sanctioned");
            dt.Columns.Add("postname");
            dt.Columns.Add("post_id");
            dt.Columns.Add("inposition");
            dt.Columns.Add("vacant");
            dt.Columns.Add("PaydrawalOrders");
            dt.Columns.Add("SupernumeraryPost");
            dt.Columns.Add("DeployedWorkingWithoutPost");
            dt.Columns.Add("InpositionOnly");
            dt.Columns.Add("NonTeachingInpositionSamagra");
            dt.Columns.Add("Remarks");

            dt.Rows.Add("sanctioned-1", "postname", "post_id", "inposition", "vacant", "PaydrawalOrders", "SupernumeraryPost", "DeployedWorkingWithoutPost", "InpositionOnly", "NonTeachingInpositionSamagra", "Remarks");
            dt.Rows.Add("sanctioned-2", "postname", "post_id", "inposition", "vacant", "PaydrawalOrders", "SupernumeraryPost", "DeployedWorkingWithoutPost", "InpositionOnly", "NonTeachingInpositionSamagra", "Remarks");
            dt.Rows.Add("sanctioned-3", "postname", "post_id", "inposition", "vacant", "PaydrawalOrders", "SupernumeraryPost", "DeployedWorkingWithoutPost", "InpositionOnly", "NonTeachingInpositionSamagra", "Remarks");
            dt.Rows.Add("sanctioned-4", "postname", "post_id", "inposition", "vacant", "PaydrawalOrders", "SupernumeraryPost", "DeployedWorkingWithoutPost", "InpositionOnly", "NonTeachingInpositionSamagra", "Remarks");
            dt.Rows.Add("sanctioned-5", "postname", "post_id", "inposition", "vacant", "PaydrawalOrders", "SupernumeraryPost", "DeployedWorkingWithoutPost", "InpositionOnly", "NonTeachingInpositionSamagra", "Remarks");

            repeater1.DataSource = dt;
            repeater1.DataBind();
        }
        catch (Exception ex)
        {
            throw;
        }
    }

    protected void LinkButtonUpdate_Click(object sender, EventArgs e)
    {

    }