SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change Class of html link in Master Page

    Hi,

    I am in process of learning ASP.net. I need to know how to change class of a link which is in Mater page from Default.aspx

    For example, in following example I would like to change/update the class of "Home" link.
    <div align="right">
    <a href="Default.aspx" id="lnkHome" class="">Home</a>
    <a href="AboutUs.aspx" id="lnkAbout" class="">About Us</a>
    <div class="Clear"></div>
    </div>
    As I am learning ASP.net, so please suggest the ways to do above.



    Thanks!

  2. #2
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    On your master page code behind create a method like this:
    public string MyLinkClass
    {
    set { mylink.attributes.add("class",value; }
    }

    Then on any page you like to set the class for that link:
    MyMasterPage master=(MyMasterPage)this.Page.Master;
    if(master!=null)
    {
    master.MyLinkClass="someclass";
    }

  3. #3
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for your response.
    The given solution is not working on my end, as it says "lnkHome" is not declared. Again the html code I have is:
    <a href="Default.aspx" id="lnkHome" class="">Home</a>
    Is there any way to access HTML elements (not asp.net html elements that run at server)?

  4. #4
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you are missing the runat="server" attribute.

    <a href="Default.aspx" id="lnkHome" class="">Home</a>
    should be
    <a href="Default.aspx" id="lnkHome" runat="server" class="">Home</a>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •