I have some link buttons in which I am dynamically adding a style to it. I am doing the following in a method:
LinkButton lb = new LinkButton(); lb.Style['font-weight'] = 'bold';
When the another link is clicked, it should unbold the link button that is bold and bold the currently clicked one, so in the method that is doing this, I have tried:
lb.Style['font-weight'] = 'none';
The above does not work though, the previously selected link stays bold.
I just realized the possible problem. I am creating multiple links and what it looks like is that since all the links are named lb, it never removes the bold. I am trying to think of a way for it to remember the previously selected link and to only unbold that one.
Can I suggest an alternative approach?
Set a CSS Style:
When a link is clicked set that link’s CSS class to ‘selected’ and the others to ”;
EDIT: To accommodate for existing Css Class
You can quickly get into trouble when defining inline styles, in that they’re difficult to overwrite.
EDIT 2:
Something like this code should work. You may have to loop through all the LinkButtons in the list, but I don’t think so. I’d just turn off ViewState on the LinkButtons.