Link to home
Create AccountLog in
Avatar of Vincent Stack
Vincent StackFlag for Qatar

asked on

How Do I find a control on masterpage from a content page

Hi Experts,

I am using masterpages with a menu set up via hyperlinks as listitems.

I am trying to reference the hyperlinks to appy the "current" CSS Class. I cannot find the link.  I am using the following in page load but I cannot 'find' the control.

 Dim mpHyperLinkHome As HyperLink = CType(Master.FindControl("HyperLinkHomeMaster"), HyperLink)
            If mpHyperLinkHome Is Nothing Then
                Response.Write("no find the link")

            Else
                mpHyperLinkHome.CssClass = "current"
            End If

..... in Masterpage
<nav>
                <ul class="sf-menu">
                   
                    <li>
                        <asp:HyperLink ID="HyperLinkHomeMaster" runat="server" NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li>
                    <li><a href="index-1.html">Services</a>
                        <ul>
                            <li><a href="#">Production practice</a></li>
                            <li><a href="#">Genetic engineering</a></li>
                            <li><a href="#">Costs and benefits</a>
                                  <ul>
                                      <li><a href="#">Procesing</a></li>
                                    <li><a href="#">Distribution</a></li>
                                    <li><a href="#">Marketing</a></li>
                                </ul>
                            </li>
                            <li class="last"><a href="#">Economics and agriculture</a></li>
                        </ul>
                    </li>
                    <li><a href="products.aspx">Products</a></li>
                    <li><a href="index-3.html">Technology</a></li>
                    <li><a href="index-4.html">Contact Us</a></li>
                </ul>
            </nav>
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Vincent Stack

ASKER

This definitely finds the hyperlink since I can change the text.  My style sheet, however, is not being applied.  Might this have to do with the page cycle?
Hard to tell without knowing all the css rules being applied to this control. Easy way to find it is to use IE dev tools (Press F12) and find which rules are applied to your control.
Please ask a new question stating your issue and providing all css rules applied to the page related to hyperlink controls.