Search code examples
asp.netcssvb.netlinkbutton

ASP.NET: How to access parent list item element from linkbutton?


I have the following situation...

<li><asp:LinkButton ID="LinkButton1" runat="server">Link</asp:LinkButton></li>

I'm wanting to be able to set the class (or add to the class attribute) of my list item when I click on the button. So once I click on the LinkButton I want the code to change to something like the following...

<li class="selected"><asp:LinkButton ID="LinkButton1" runat="server">Link</asp:LinkButton></li>

Thanks!


Solution

  • It is better to perform this on the server, as the response will re-render the page. Thus, making JavaScript changes non-applicable:

    Dim parent As HtmlControl = LinkButton1.Parent
    parent.Attributes("class") = "selected"