我动态地将按钮添加到 ListView ,并使用 ItemCommand 事件处理按钮单击事件,使用按钮的 CommandName 属性。它在 IE 中运行良好,但当我在 Firefox 5 中尝试时,它会触发页面加载事件而不是 ItemCommand 事件。 Firefox 有解决方法吗?
谢谢!
<asp:ListView ID="lvItems" runat="server" OnItemDataBound="lvItems_ItemDataBound" DataSourceID="odsItems" OnItemCommand="lvItems_ItemCommand" DataKeyNames="ItemID" OnDataBound="lvItems_DataBound" OnPagePropertiesChanging="lvItems_PagePropertiesChanging"> <LayoutTemplate> <div id="itemPlaceholder" runat="server"> </div> </LayoutTemplate> <ItemTemplate> <div> <asp:Label ID="lbl" runat="server"> </asp:Label> <asp:Button ID="btnAdd" runat="server" CommandName="Add" Text="Add" OnClientClick="this.disabled=true;" /> </div> </ItemTemplate> <EmptyDataTemplate> No items found for the selected filters. Please try again.<br /> <br /> </EmptyDataTemplate> </asp:ListView> protected void lvItems_ItemCommand(object sender,ListViewCommandEventArgs e) { if (e.CommandName == "Add") { //code here; } }
最佳答案
你必须设置 UseSubmitBehaviour为 false
,因为在客户端禁用按钮将取消浏览器提交。顺便说一下,在 IE 中是完全一样的。
<asp:Button ID="btnAdd" runat="server" CommandName="Add" Text="Add"
UseSubmitBehavior="false" OnClientClick="this.disabled='true';" />
通过这种方式,ASP.NET 将在脚本末尾附加必要的客户端脚本以回发:
__doPostBack('btnAdd','')
关于c# - ListView ItemCommand 事件未在 Firefox 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6629066/