3

Consider i have 3 linkbuttons on a page,

<asp:LinkButton ID="LB1" runat="server" CssClass="regular" OnClick="LB1_Click">
  Today
</asp:LinkButton>
<asp:LinkButton ID="LB2" runat="server" CssClass="regular" OnClick="LB2_Click">
  Today
</asp:LinkButton>
<asp:LinkButton ID="LB3" runat="server" CssClass="regular" OnClick="LB3_Click">
  Today
</asp:LinkButton>

I want to highlight a linkbutton on its click with a css and then remove its css when another linkbutton is clicked (ie) i want to show active link button. Any suggestion.

2
  • Just to clarify the active link part - Because you are not removing the changed css till the next time the user clicks a button, the changed style will actually indicate the last action taken by the user- is that what u mean by active link? Commented Aug 14, 2010 at 11:41
  • @In Sane ya exactly that is what i want. Commented Aug 14, 2010 at 11:43

2 Answers 2

2

I'm using jquery-ui and I assign a class abtn to each button (input type=submit or a href)

I'n the page load I execute this:

function dobuttons() {
        $(".abtn").hover(
            function () {
                $(this).addClass("ui-state-hover");
            },
            function () {
                $(this).removeClass("ui-state-hover");
            }).bind({

                'mousedown mouseup': function () {
                    $(this).toggleClass('ui-state-active');
                }

            }).addClass("ui-state-default").addClass("ui-corner-all")
            .bind('mouseleave', function(){$(this).removeClass('ui-state-active')});
    }

you can see live sample here http://mrgsp.md:8080/a/Dossier/Create

Sign up to request clarification or add additional context in comments.

Comments

1

In Page_Load, you set the css class of all the linkbuttons to default class

LB1.CssClass = "StandardClass";
LB2.CssClass = "StandardClass";

....

And in the Btn_Click event of each LinkButton, you set its css class to the "Active" css

Eg : If LB1 is clicked then within LB1_Click

LB1.CssClass = "ActiveClass";

This seems straight forward enough. Hope i am not mis-understanding something in your question.

1 Comment

@Pandiya --- whoopsie!! :-) I just knew it wouldnt be something that simple!! Cant help with Jquery but maybe Omu's answer will do it for you!! BTW, maybe adding JQuery to the list of tags - would not confuse a relative noob like me!! :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.