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

  • SEARCH
  • Home
  • 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 984477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:01:23+00:00 2026-05-16T05:01:23+00:00

I have a search page that is used in multiple places with multiple ‘themes’

  • 0

I have a search page that is used in multiple places with multiple ‘themes’ throughout my site. I have a few divs that can have their background color changed based on a radio button selection (whether they are enabled or not). I can do this just fine by changing the css class of the div on the fly with javascript.

However, these themes could potentially change, and the background color is grabbed from a database when the page is created. Right now I do this in the C# codebehind:

string bgStyle = "background-color:" +theme.searchTextHeaderColor +";";
OwnerSearchHeader.Attributes.Add("style", bgStyle);

In the Javascript I need to change this color to make it look disabled, and when the user clicks back to this div I need to re-enable it by changing it back to its original color. But since I only knew this color in the code-behind, I don’t know what it was in the Javascript.

So my thought was to create a css class in the resulting HTML page when the page is loaded with the background color I need. Then I could simply switch from the divEnabled and divDisabled class in the javascript. But I’m not exactly sure how to do that.

Alternatively I could create a hidden element, assign it the ‘enabled’ style, and use that as a reference in the JavaScript when enabling my div. This seems like a hack but maybe its the easiest way. I’m still new to a lot of this, so I’d appreciate any suggestions. Thanks for the input!

  • 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-05-16T05:01:24+00:00Added an answer on May 16, 2026 at 5:01 am

    So my thought was to create a css class in the resulting HTML page when the page is loaded with the background color I need. Then I could simply switch from the divEnabled and divDisabled class in the javascript. But I’m not exactly sure how to do that.

    Yes, this is the anser; do this. In the <head> of your document add a <style> and put your CSS in there like so: (my Asp.NET is a little rusty so forgive me if it has some hicups 😉 )

    <style>
        <!--
        .divEnabled {
            background-color:<%=theme.searchTextHeaderColor%>;
        }
        .divDisabled {
            background-color:gray; /* or wtv */
        }
        -->
    </style>
    

    You could also put it in an external CSS file, which may be a good idea.

    Then write some JavaScript to add/remove the class attribute (I’m going to ask that you don’t call is the “CSS Class” 😉 )

    var ownersearchheader = document.getElementById("<%=OwnerSearchHeader.ClientId%>");
    // changing the class attribute to `divDisabled`
    var newClassAttribute = ownersearchheader.getAttribute("class").replace(/\bdivEnabled\b/, "divDisabled")
    ownersearchheader.setAttribute("class", newClassAttribute);
    // ... or,
    // changing the class attribute to `divEnabled`
    var newClassAttribute = ownersearchheader.getAttribute("class").replace(/\bdivDisabled\b/, "divEnabled")
    ownersearchheader.setAttribute("class", newClassAttribute);
    

    This is indeed a mouthfull, so, like @Haydar says, you might want to use jQuery, which offers easy-as-pie addClass(), removeClass() and toggleClass() methods.

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

Sidebar

Related Questions

I have a search page on my MVC site that contains a list of
I have a search functionality on my site that is accessible from every page.
I have a search page that if there is results in the list it
I currently have an advanced search page that searches a number of fields in
I have an ASP.NET page that contains two div's. Both have search fields and
I have a live search on my help page that searches our help database
I have a page that displays search results and has a DOM like the
I have a search page in which I am searching data by passing multiple
I have an Classic ASP page that lets users search for properties and a
I have a site that used to host on a free hosting service. A

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.