Re: Change color of selected hyperlink in a masterpage
Hey,
You should definitely be able to do this, but it may be a combination of things that is making it not work. The first thing you need to rule out is that there aren't any other styles overriding what it is you think you are doing.
The easiest way that I have found to do this is to use the FireBug Addin for firefox. If you haven't used this before, I would thoroughly recommend it. It allows you to inspect any html element, and looks at all the styles that are being applied to it, see the screen shot here:
Hopefully you can see that I have selected the element which contains your name, and on the right hand side you can see all the CSS being applied.
Have a look here for an introduction to using FireBug:
Hopefully armed with these tools you will be able to figure out what you want to do. I am hesitant to jump in with a solution at this point because I have found that CSS is something best learnt by doing. If you are struggling though, post back.
Re: Change color of selected hyperlink in a masterpage
I think you might be misunderstanding the :active pseudo class for the menu item's active item - it's probably just semantics.
In CSS, :active specifies the style for the hyperlink when you are clicking it. In your context, you want to change the style of the currently selected menu item - the CSS has no way of knowing what an accordion control is or what the concept of 'active' means here.
If you're using the Accordion AJAX control, then it has certain properties you can use (example)
Re: Change color of selected hyperlink in a masterpage
I'm still battling with this. At one point I had something working..Where it was fixing the selected item as bold until something else was selected. I have stripped it back to a starting point. Hoping that someone can show me what the problem is. I would have thought that defining the HeaderCssClass, HeaderSelectedCssClass & ContentCssClass with the Accordion would cascade the style. It doesn't seem to do anything.
Re: Change color of selected hyperlink in a masterpage
Yea..I've been trying to use that tutorial to understand it but it's not much help.
He defines the HeaderCssClass class but then overrides it with a .accordionlink class. The ContentCssClass is also overridden.
So the HeaderCssClass and ContentCssClass never actually get used.
I need to use them and want to differentiate between HeaderCssClass & HeaderSelectedCssClass. My next problem is that there is no ContentSelectedCssClass property in the accordion control.
Re: Change color of selected hyperlink in a masterpage
Hey,
I am not sure I understand what your problem is, the HeaderCssClass and the ContentCssClass are used?!?! Have you downloaded the sample code and had a look?
The example clearly shows how you can use the HeaderCssClass and ContentCssClass. In addition, the author of the sample has then used additional CSS Classes to separately define the anchor tags. This is probably due to the fact that the same style is applied to other anchor tags, not solely to anchor tags that exist within the Header of the Accordion.
How you structure your CSS is up to you, it is personal preference.
You are correct when you say that there isn't a ContentSelectedCssClass, but I am unclear why you need this? The purpose of the Accordion is that only one pane is visible at a time, as a result, you don't need a separate CSS Class for the content, you only need one.
Re: Change color of selected hyperlink in a masterpage
A hyperlink is considered to be an active hyperlink from the time a user presses and releases the mouse button when clicking on the hyperlink. When designing a Web page, you can choose a font color to represent active hyperlinks.
I can't see the point to this as the the time between a person pressing and releasing on a hyperlink should be only a fraction of a second. So I still have the problem of setting a style to a selected hyperlink in the masterpage after the child page has loaded.
Re: Change color of selected hyperlink in a masterpage
Hej,
Thanks for your help here.
I have a list of hyperlinks in the left hand table menu of a masterpage that to link to different pages.
If I click on each link then I want it to remain highlighted somehow that I am currently at that page.
Re: Change color of selected hyperlink in a masterpage
Hey,
Are we still talking about the link within the header of the Accordion Control? If we are, then surely the fact that the content for that pane of the accordion control being visible should be enough of an indication. No?
If not, then how about making the following change to the sample that you downloaded from the video I linked to earlier.
Edit the StyleSheet.css to the following (notice the parts in bold that have changed):
Notice I have removed the class from the anchor tag. Instead, the style for the a in the CSS file is used. If you use the above, then you should see that the link is Aqua when selected, and Green when not. Also, I have added the HeaderSelectedCssClass to the definition of the Accordion control.
It isn't particularly nice to look at, but it is just to emphasize the point.
Re: Change color of selected hyperlink in a masterpage
Thanks gep13,
I still have a problem with hyperlink items being selected in the Content.
I found the attached example that solves the problem but it is written in C#. Can anyone convert it to VB for me?
Re: Change color of selected hyperlink in a masterpage
I've finally worked it out.
In each page linked from the accordion menu needs to have this page load event:
Code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim hl As HyperLink = Master.FindControl("HyperlinkID")
hl.CssClass = "MenuSelected"
End Sub
End Class
Re: [RESOLVED] Change color of selected hyperlink in a masterpage
It's possible to change it if the tag has runat="server" and an ID.
Did setting the CssClass not work? In addition to the CssClass property, you have access to the .Styles collection as well as the .Attributes collection.
Re: [RESOLVED] Change color of selected hyperlink in a masterpage
This
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim hl As HyperLink = Master.FindControl("lnk1")
hl.CssClass = "Selected"
End Sub
works ok if the hyperlink is embeded in the form but not if the hyperlink is in the accordion. Can anyone suggest how to modify the code above to find the hyperlink control in the accordion control?
Re: [RESOLVED] Change color of selected hyperlink in a masterpage
Hey,
Simply doing a FindControl on the Master will not find the controls that exist within the Accordion. This is being the Accordion Control in a control container, and as such, you will need to recurse into the Accordion to find the controls within in.
You can do this by doing something like the following:
Code:
Master.MyAccordion.Panes[0].FindControl
Where this is finding the controls in the first Pane of the Accordion. Whenever you are using the FindControl method, you should always first check to see whether the method has returned null (i.e. is hasn't found the control) before accessing properties or methods of that control.