Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:49:14+00:00 2026-06-09T18:49:14+00:00

I have some CSS that controls my asp:LinkButton hyperlinks, and I want to find

  • 0

I have some CSS that controls my asp:LinkButton hyperlinks, and I want to find out how I can set the WebControl’s CssClass property for the current page whenever the MasterPage loads.

These asp:LinkButton hyperlinks on the MasterPage are contained in a list:

<ul id="menu">
  <li class="sprite">
    <asp:LinkButton ID="linkButton1" runat="server" PostBackUrl="~/linkButton1.aspx">
      <span>link 1</span>
    </asp:LinkButton>
  </li>
  <li class="sprite">
    <asp:LinkButton ID="linkButton2" runat="server" PostBackUrl="~/linkButton2.aspx">
      <span>link 2</span>
    </asp:LinkButton>
  </li>
  <li class="sprite">
    <asp:LinkButton ID="linkButton3" runat="server" PostBackUrl="~/linkButton3.aspx">
      <span>link 3</span>
    </asp:LinkButton>
  </li>
</ul>

In the MasterPage I have tried to set the CssClass using the Page_Load event:

protected void Page_Load(object sender, EventArgs e) {
  if (!IsPostBack) {
    linkButton1.CssClass = "";
    linkButton2.CssClass = "";
    linkButton3.CssClass = "";
    string linkButtonID = Request.RawUrl;
    if (-1 < linkButtonID.IndexOf("linkButton2")) {
      linkButton2.CssClass = "active";
    } else if (-1 < linkButtonID.IndexOf("linkButton3")) {
      linkButton3.CssClass = "active";
    } else {
      linkButton1.CssClass = "active"; // default
    }
  }
}

My CssClass="active" does not appear to ever be set, and looking at the page source quickly verifies that none of my LinkButton controls has the CssClass property set.

Since this is hard to visualize, I’ve put together a jsFiddle. The site does not support ASP, but it may help you visualize what I am trying to accomplish:

http://jsfiddle.net/jp2code/kZQwC/

How would I get my Active Page to set the CssClass?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:49:15+00:00Added an answer on June 9, 2026 at 6:49 pm

    You are assign the class in !IsPostBack I am afraid that your url at that time is not having linkButton1, linkButton2 or linkButton3.

    You take the class assignment code out of the if condition and check if you that those condition executed and getting the class.

    Change

    if (!IsPostBack) {
        linkButton1.CssClass = "";
        linkButton2.CssClass = "";
        linkButton3.CssClass = "";
        string linkButtonID = Request.RawUrl;
        if (-1 < linkButtonID.IndexOf("linkButton2")) {
          linkButton2.CssClass = "active";
        } else if (-1 < linkButtonID.IndexOf("linkButton3")) {
          linkButton3.CssClass = "active";
        } else {
          linkButton1.CssClass = "active"; // default
        }
    }
    

    To

    linkButton1.CssClass = "";
    linkButton2.CssClass = "";
    linkButton3.CssClass = "";
    string linkButtonID = Request.RawUrl;
    if (-1 < linkButtonID.IndexOf("linkButton2")) {
      linkButton2.CssClass = "active";
    } else if (-1 < linkButtonID.IndexOf("linkButton3")) {
      linkButton3.CssClass = "active";
    } else {
      linkButton1.CssClass = "active"; // default
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within an asp.net webform I have some jquery that controls the positioning of elements
I have some CSS that doesn't behave correctly with IE8. It works fine with
I have some CSS style that does not work in IE and that works
I have some css files that i need to use in RTL direction template.
I have some CSS and HTML for horizontal tabs that works perfectly in jsfiddle.
I have written some JS and CSS that allows certain columns to be flexible
I have some questions regarding the following css that I found: html, body {
I'm writing a webmail product and some emails have body css that changes the
I have a php script that uses some css/javascript tabs, they work on my
I have a page with some very basic examples that use HTML/CSS/JavaScript. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.