tags:

views:

245

answers:

3

i have one aspx page on which. set of linkbuttons on it.

linkbutton1

linkbutton2

linkbutton3

linkbutton4

linkbutton5

if i click on any of them. it should be highlighted.

These linkbuttons are in the table.

thanks for any help.

A: 

I build the same in my pages the last weeks often.

As I see you have 2 options, regarding your code behind, that I don't know:

1) Your link button are linked to a special site (as hyperlinks). Than you can found out by the actual site which is clicked an hover it.

2) Your linkbutton only acitvate code, than you can make a normal "linkbutton1.Font.Bold = true" or something like this.

If you want it by CSS as my knowlegde it is not possible, because there are not rendered as a -tag.

Kovu
i can do that in .net using some code. which is very perfect if you want to see it. i will tell you. give me comment. i will put it here. for you. but your answer is absolutely down track
Sikender
its not working!!!!
Sikender
+8  A: 

If you add a CssClass to any of your linkbuttons, something like

<asp:LinkButton ID="LinkButton1" runat="server" CssClass="linkbtn" />

You can define the highlighted style in CSS like

.linkbtn .highlighted { color: red; }

and use some javascript to toggle classes. In jQuery it would look like:

$(".linkbtn").click(function () {
   $(".linkbtn").removeClass("highlighted");
   $(this).addClass("highlighted");
});


in ASP.Net just use

<asp:LinkButton id="LinkButton4" OnClick="LinkButton4_Click" runat="server"/>

and in codebehind

private void SetHighlighted(LinkButton btn)
{
  LinkButton1.CssClass = "";
  LinkButton2.CssClass = "";
  LinkButton3.CssClass = "";
  LinkButton4.CssClass = "";
  LinkButton5.CssClass = "";

  btn.CssClass = "highlighted";
}

protected void LinkButton4_Click(object sender, EventArgs e)
{
  SetHighlighted((LinkButton)sender);
}

do this for every linkbutton

Jan Jongboom
no. dont want jquery...
Sikender
See edit for ASP.Net example.
Jan Jongboom
be sure that each linkbutton points to LinkButton4_Click as it's OnClick event handler. just for clarification...
hey!!! for css style sheet i am doing this much of coding? Is it good thing as per the programing point of view?
Sikender
thank you very much.. for these much of work. but it is very much longer than i should expect. sorry buddy
Sikender
Downvote reason?! The solution does exactly what Sikender asks.
Jan Jongboom
I agree, you can set the styles of the links when clicked, so i dont think this deserves a downvote...
trace
hope the thread starter wouldn't mind, would you care to show us what you have done so far as to help you specifically on what you want achieved and how you want it written?
trace
+1 Not only because this is the correct answer which takes multiple views into account, but also because whoever down voted it was obviously an idiot. It's a bit strange how everyone got a down vote and every single comment by Sikender got an up vote... weird. But nice work Jan, perfectly done with absolute minimal information.
Jay
it's working. if i add .js file. its a good code. and exactly . what i am saying. but if i have more than 5 buttons means. 10 and above buttons, so much coding is needed. anyway. i did it as my own ways. thanks. thank you. so much.
Sikender
+3  A: 

you can easily take care of this with css.

when you handle the linkbutton click event set the CSSClass property of the linkbutton to a class which differentiates it from the other linkbuttons in the list.

for instance, on page load you can have all linkbuttons CSSClass property set to Link and have this class defined to be your standard look and feel for hyperlinks. 8pt, tahoma, underlined etc.

create another class called LinkSelected and have it be 8pt, tahoma, underlined, and bold.

in your linkbutton click handler set myLink.CSSClass="LinkSelected"; or ((LinkButton)sender).CSSClass="LinkSelected";

you can define Link and LinkSelected class either inline (not recommended) or in a separate .css file.

give it a try and let me know if you need more details.

yes. i want to know this in detail. its not working
Sikender
jans answer is exactly what i would add for detail.
Try to refresh your cache browser.
Ucodia