Search code examples
javascriptasp.netlinkbutton

ASP.NET Change link button color when clicked without post-back or update panel


in an asp.net page I have a list of Link buttons:

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Link_Click">Link 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="Link_Click">Link 2</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server" OnClick="Link_Click">Link 3</asp:LinkButton>

I am using them as triggers for an update panel on the site. When a user clicks on a link a control gets loaded on the page.

What I want is this:

Whne the user clicks on a link the color of that link change so we can know which link was pressed last.

I would like to do this without post-back or update panels. So is there a way to do this via javascript? or other solutions?

Thank you for any help


Solution

  • JAVASCRIPT:

    <script>
        function changeColor(e) {
            e.style.color = "red";
            return false;
        }
    </script>
    

    HTML:

    <asp:LinkButton ID="LinkButton1" OnClientClick="return changeColor(this);" runat="server">LinkButton</asp:LinkButton>
    

    Good luck!