Results 1 to 2 of 2

Thread: [RESOLVED] [2005] User control Image button event handler issue...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Resolved [RESOLVED] [2005] User control Image button event handler issue...

    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:
    <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>
    code behind

    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.
    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"]);
    
        }
    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.

    If anybody has any ideas that would be great.
    If someone has helped you, please make sure to rate them.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: [RESOLVED] [2005] User control Image button event handler issue...

    We had made the viewstate of the datalist false to try to improve performance issues and apparently this also changed the page's viewstate. When i changed the datalist control's viewstate back to true the page was still false and the imagebutton's still didn't work. After getting them both set back to true, the imagebutton's events work just fine.
    If someone has helped you, please make sure to rate them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width