I have a datalist control on a usercontrol. It loads with either an imagebutton visible or a button visible. The event that I want to fire for both of these does not seem to be firing. (I noticed that there are some other posts along these lines also) I have tried setting the OnCommand in the datalist control and I have tried setting the Command event in the ItemDataBound event.
ascx
code behindCode:<asp:DataList ID="listProducts" runat="server" HorizontalAlign="Center" OnItemCommand="listProducts_ItemCommand" OnItemDataBound="listProducts_ItemDataBound" Width="100%" EnableViewState="False"> <ItemStyle VerticalAlign="Bottom" /> <HeaderTemplate> <div align="right"> <asp:Button ID="btnCart1" runat="server" CommandArgument="checkout" CssClass="style4" Text="Add to Cart" /> </div> </HeaderTemplate> <FooterTemplate> <div align="right"> <asp:Button ID="btnCart2" runat="server" CommandArgument="checkout" CssClass="style4" Text="Add to Cart" /> </div> </FooterTemplate> <ItemTemplate> <table border="0" cellpadding="3" cellspacing="2" width="100%"> <tr align="center" bgcolor="#f5f5f5"> <td align="center" nowrap="nowrap" width="10%"> <asp:ImageButton ID="_detailButton" runat="server" CausesValidation="False" ImageAlign="Top" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemNum")%>' ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Graphic")%>' CommandName="detailClick" /><br /> <asp:Button ID="detailButton" runat="server" CausesValidation="False" Text="Details" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemNum")%>' CommandName="detailClick" /></td> <td align="left" valign="top" width="60%"> <asp:Label ID="prodID" runat="server" Visible="false"></asp:Label> <asp:Label ID="uniqueID" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "ItemNum") %>'></asp:Label> <asp:HyperLink ID="sku" runat="server" CssClass="style4" Text='<%# DataBinder.Eval(Container.DataItem, "ItemNum")%>'></asp:HyperLink> <br /> <asp:Label ID="shortDesc" runat="server" CssClass="style5" Text='<%# DataBinder.Eval(Container.DataItem, "Descr") %>'></asp:Label> <asp:Label ID="hiddenCat" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "Category") %>'></asp:Label></td> <td align="left" valign="top" width="30%"> <asp:Label ID="listLbl" runat="server" Text="List Price:" CssClass="style4"></asp:Label> <asp:Label ID="list" runat="server" CssClass="style5" Text='<%# DataBinder.Eval(Container.DataItem, "ListPrice") %>'></asp:Label> <br /> <asp:Label ID="yourPriceLbl" runat="server" Text="Your Price:" CssClass="style4"></asp:Label> <asp:Label ID="yourPrice" runat="server" CssClass="style5" Text="Label"></asp:Label> <br /> <asp:Label ID="uomLbl" runat="server" Text="UOM:" CssClass="style4"></asp:Label> <asp:Label ID="uom" runat="server" CssClass="style5" Text='<%# DataBinder.Eval(Container.DataItem, "Unit") %>'></asp:Label> <br /> <asp:Label ID="qtyLbl" runat="server" Text="Qty:" CssClass="style4"></asp:Label> <asp:TextBox ID="qty" runat="server" CssClass="style5" Columns="2"></asp:TextBox> <asp:CompareValidator ID="qtyCheck" runat="server" Display="Dynamic" ControlToValidate="qty" ValueToCompare="0" Operator="GreaterThanEqual" ErrorMessage="Quantity must be greater than 0"></asp:CompareValidator> <asp:RegularExpressionValidator ID="qtyValidator" runat="server" Display="Dynamic" ControlToValidate="qty" ValidationExpression="(\d{1,})+" ErrorMessage="Quantity must be a numeric value.">**</asp:RegularExpressionValidator> </td> </tr> </table> </ItemTemplate> </asp:DataList>
this is the relevant part of the ItemDataBound event
Code:#region ImageButton //image button if (String.Compare(((ImageButton)e.Item.FindControl("_detailbutton")).ImageUrl, String.Empty) == 0) { ((Button)e.Item.FindControl("detailButton")).Visible = true; ((ImageButton)e.Item.FindControl("_detailButton")).Visible = false; ((Button)e.Item.FindControl("detailButton")).Command += new CommandEventHandler(detailButtonClick); } else { ((Button)e.Item.FindControl("detailButton")).Visible = false; ((ImageButton)e.Item.FindControl("_detailButton")).Visible = true; ((ImageButton)e.Item.FindControl("_detailButton")).Command += new CommandEventHandler(detailButtonClick); } #endregion
this is the event i want to fire for both the imagebutton and the button depending on which one is visible.
I have set breakpoints in the detailButtonClick event, the ItemDataBound event, and the ItemCommand event for the datalist to check to see if that event was capturing the wrong event maybe. But when i click on the imagebutton none of the breakpoints are hit and it comes back to a blank page, not even an error.Code:protected void detailButtonClick(object sender, CommandEventArgs e) { string SubCatID = (Request.QueryString["SubCatID"] == null || Request.QueryString["SubCatID"] == String.Empty) ? "0001" : Request.QueryString["SubCatID"]; Response.Redirect("storefront.aspx?SubCatID=" + SubCatID + "&CatalogID=" + Request.QueryString["CatalogID"] + "&ProductID=" + e.CommandArgument.ToString() + "&CategoryID=" + Request.QueryString["CategoryID"] ); //+ "&SkuGroup=" + Request.QueryString["SkuGroup"]); }
If anybody has any ideas that would be great.



Reply With Quote