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 8919235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:58:04+00:00 2026-06-15T05:58:04+00:00

I am trying to put CssClass to a link Button of Navigation Menu. It

  • 0

I am trying to put CssClass to a link Button of Navigation Menu.
It is because when i click on to the link Button it sets its class to active.
Here I got error creating controls.

<div class="navigation">
<ul>
<li class="homenavBt">
<asp:LinkButton ID="LinkHome" runat="server" <% If Session("Page")="Home" Then %> CssClass="active" <% End If %> >Home</asp:LinkButton></li>
<li class="newsBt">
<asp:LinkButton ID="LinkNews" runat="server"  <% If Session("Page")="News" Then %> CssClass="active" <% End If %> >News</asp:LinkButton></li>
<li class="sportsbt">
<asp:LinkButton ID="LinkSports" runat="server"  <% If Session("Page")="Sports" Then %> CssClass="active" <% End If %> >Sports</asp:LinkButton></li>
<li class="glamournavBt">
<asp:LinkButton ID="LinkArticle" runat="server"  <% If Session("Page")="Article" Then %> CssClass="active" <% End If %> >Article</asp:LinkButton></li>
<li class="technav_bt">
<asp:LinkButton ID="LinkGallery" runat="server"  <% If Session("Page")="Gallery" Then %> CssClass="active" <% End If %>>Gallery</asp:LinkButton></li>
</ul>
</div>

When i click on the link Button i need to set Session for respective pages, just like below.

Protected Sub LinkNews_Click(sender As Object, e As EventArgs) Handles LinkNews.Click
        Session("Page")="News"
End Sub

Please comment if something is not cleared
Thanks!!

  • 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-15T05:58:05+00:00Added an answer on June 15, 2026 at 5:58 am

    The reason you’re having this problem is that you can’t put in-line code into controls with runat=”server”, unless you use the data binding syntax: <%# …%>, and call DataBind() from your code.

    Well, here’s how you could possibly do it, using your code behind (in C#):

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckPage();
    }
    
    private void CheckPage()
    {
        if (Session["Page"] as string == "News")
            LinkNews.CssClass = "active";
        else
            LinkNews.CssClass = String.Empty;
    }
    
    protected void LinkNews_Click(object sender, EventArgs e)
    {
        Session["Page"] = "News";
        CheckPage();
    }
    

    …in which case you wouldn’t specify a CSS class in your markup:

    <div class="navigation">
    <ul>
    <li class="homenavBt">
    <asp:LinkButton ID="LinkHome" runat="server">Home</asp:LinkButton></li>
    <li class="newsBt">
    <asp:LinkButton ID="LinkNews" runat="server">News</asp:LinkButton></li>
    <li class="sportsbt">
    <asp:LinkButton ID="LinkSports" runat="server">Sports</asp:LinkButton></li>
    <li class="glamournavBt">
    <asp:LinkButton ID="LinkArticle" runat="server">Article</asp:LinkButton></li>
    <li class="technav_bt">
    <asp:LinkButton ID="LinkGallery" runat="server">Gallery</asp:LinkButton></li>
    </ul>
    </div>
    

    If you want to use the binding technique, it might look something like this (again C#):

    <asp:LinkButton ID="LinkNews" runat="server" CssClass='<%# Session["Page"] as string == "News" ? "active" : "" %>'>News</asp:LinkButton>
    

    … and you will have to call DataBind() from your code, instead of CheckPage() (in my previous example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to put together a 3-tiered array of term, class, students for a waitlist
I trying to put the text of a JLabel under its icon (centered) at
I have a standard ul-based CSS navigation menu. I'm trying to use Jquery to
iam trying to put the div menu above the object tag but still under
I am trying to put an arrow sign in the round rect button. I
I'm trying to put into XML-file some data. Here is the code: @Test public
I am trying to put bar to close to black footer its working in
I'm trying put an if statement directly into a select field in rails, with
Trying to put a regex expression together that returns the string between _ and
I trying to put together an Android app that will take a picture and

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.