asp.net无效回发按钮onclick在转发器页脚

时间:2016-06-14 14:45:03

标签: c# asp.net

给出以下页面(最新更新)。

 <%@ Page Title="" Language="C#" MasterPageFile="~/master/superuser.master" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="permissions_default" %>

 <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server"></asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="PageContent" runat="Server">
  <h1>Permissions Management</h1>
<div class="row">
      <div class="span9">
        <form runat="server">
            <fieldset>
                <legend>CRM User Permissions</legend>
                <asp:Repeater ID="rptUserPermissions" runat="server" OnItemCommand="rptUserPermissions_ItemCommand">
                    <HeaderTemplate>
                        <table class="table table-striped autowidth">
                            <thead>
                                <tr>
                                    <th>User</th>
                                    <th>Program</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                    </HeaderTemplate>

                    <ItemTemplate>
                        <tr>
                            <td><%# DataBinder.Eval(Container, "DataItem.user_name") %></td>
                            <td><%# DataBinder.Eval(Container, "DataItem.program_name") %></td>
                            <td>
                                <asp:Button ID="btnDelete" Text="Delete" runat="server" CommandName="cmd_Delete" CommandArgument="<%# DataBinder.Eval(Container, "DataItem.id") %>" />
                            </td>
                        </tr>
                    </ItemTemplate>

                    <FooterTemplate>
                        <tr>
                            <td>
                                <asp:DropDownList ID="ddUser" runat="server" />
                            </td>
                            <td>
                                <asp:DropDownList ID="ddProgram" runat="server" />
                            </td>
                            <td>
                                <asp:Button ID="btnSubmit" Text="Add New" runat="server" CommandName="cmd_Submit"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    </FooterTemplate>
                </asp:Repeater>
            </fieldset>
        </form>
    </div>
    <div class="span1">&nbsp;</div>
    <div class="span4"></div>
  </div>
</asp:Content>
 <asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="Server">
</asp:Content>

如何处理转发器页脚中btnSubmit和btnDelete的按钮onclick事件,而不会引发无效的回发或回调异常?

更新:使用命令参数在delete btn上输入databinder.evals现在抛出一个解析erorr消息,内容如下:

Parser Error Message: The server tag is not well formed.

1 个答案:

答案 0 :(得分:1)

您实际上想要使用通过项目模板中的按钮按下触发的itemcommand事件。在你可以使用的行的上下文中传递。

你可以在这里看到一个例子:

http://nazimakul.com/article/repeater-itemcommand-event-in-asp-net_1049