我正在动态地将按钮添加到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','')
- http://encosia.com/disable-a-button-control-during-postback/
- OnclientClick和OnClick不同时工作?