Search code examples
c#eventsfirefoxlistviewitemcommand

ListView ItemCommand Event Not Firing in Firefox


I am dynamically adding buttons to a listview and using the ItemCommand event to handle the button click event using the CommandName property for the button. It works fine in IE, but when I try in Firefox 5, it is hitting the page load event but not the ItemCommand event. Is there a work-around for Firefox?

Thanks!

<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; 
    }
}

Solution

  • You have to set UseSubmitBehaviour to false, because disabling a button on clientside will cancel the browsers submit. By the way, in IE it's exactly the same.

    <asp:Button ID="btnAdd" runat="server" CommandName="Add" Text="Add"
       UseSubmitBehavior="false" OnClientClick="this.disabled='true';" />
    

    On this way ASP.NET will append the necessary client-script to postback at the end of your script:

    __doPostBack('btnAdd','')