-1

Sample ImageI have a listview in which a div has an image, a wishlist button and a add to cart button. When i click on wishlist the text does not change in listview_itemcode event. Below is code;

<asp:ListView ID="usrListShowImages" runat="server" OnItemCommand="usrListShowImages_ItemCommand">
<LayoutTemplate>
    <table id="MainTablePlaceHolder" style="border:20px Orange; width:100%;" >
        <tr style="border:5px orange;">

        </tr>
        <tr runat="server" id="itemPlaceHolder" style="border:2px Orange" />
    </table>
</LayoutTemplate>
<ItemTemplate>
    <tr>
            <asp:UpdatePanel runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
                <ContentTemplate>
                <asp:HyperLink ID="hypLink" NavigateUrl="http://www.google.com" runat="server" >

                    <div class="wishlist">
                        <div class="growuser picUserShow">

                <asp:Image ID="userShowImgz" ClientIDMode="Static"
                    ImageUrl='<%# ".." + Eval("ItemsPicUrl") %>' runat="server" />
                    </asp:HyperLink>

                <div class="bottomDiv"> 

                    <asp:Button ID="btnWhishlist" Text="Wishlist" runat="server" CssClass="wishlistButton" CommandName="btnWhishlist" UseSubmitBehavior="false" />

                </div>
                    </div>
                        </div>



                    <%-- <asp:Label ID="lblShow" runat="server" Text="Label"></asp:Label>--%>

            </ContentTemplate>

            </asp:UpdatePanel>            

    </tr>
</ItemTemplate>

Any help would be highly appreciated

user1489440
  • 7
  • 1
  • 7

2 Answers2

0

Couldn't understand the question, but your tags are little messy and it might be crossing with the lines of the update panels. you should use table-tr-td-/td-/tr-/table in the correct order to create a proper HTML table.

Pecheneg
  • 768
  • 3
  • 11
  • 27
  • Thanks Necati, actually problem is that I want to change text of the button that is clicked, "Wishlist" to "Added to Wishlist", I'll try to upload a screen shot – user1489440 Feb 29 '16 at 17:09
  • No problem, the error message would also help, check the script console of your browser if you don't get one from debugging. – Pecheneg Feb 29 '16 at 17:37
  • Actually there is no error, only the text remains as is. I need to change it. – user1489440 Feb 29 '16 at 17:43
  • I have attached an image, hope this helps @Necati Hakan Erdogan – user1489440 Mar 01 '16 at 12:43
  • Hey mate, it may be remains as it is, but there might be some Javascript error which doesn't show up in debug console, but you can see it from your browser. I also suggest you to implement features one by one, (e.g. listview first, then scripts, then updatepanel etc.) which simply helps you to see what part of the code is causing the problem. – Pecheneg Mar 01 '16 at 16:28
  • thanks Necati, I'll try them one by one and share my feedback. – user1489440 Mar 02 '16 at 17:38
0

There are two ways of changing text when button (control) is inside a listview (another control).

  1. listview_ItemCommand event in code behind.

    protected void usrListShowImages_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
    if (e.CommandName == "btnWhishlist")
    {
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
    Button dbutton = (Button)e.Item.FindControl("btnWhishlist");
    if (dbutton.Text == "Wishlist")
    {
    dbutton.Text = "NEW";            
    }
    
                lblTest.Text = dbutton.ID.ToString() + "text = " + dbutton.Text;
            }
        }
    }  
    

If the text doesn't appear changed, in .aspx page, just put the button (Control) inside UpdatePanel.

  1. JQuery

jQuery: Change button text on click This post will also help.

Community
  • 1
  • 1
user1489440
  • 7
  • 1
  • 7