Tips for altering the appearance of a button when moving to a related page

I have a master page with four buttons that have a mouse hover CSS property. Each button's corresponding response page is defined on the same master page. Now, I want to change the button style when the user is on the corresponding page. How can this be achieved? The code in my master page is as follows:

<style type="text/css">
.side_btn_css {
 width: 200px;
 height: 85px;
 font-size: 20px;
 color: #fff;
 line-height:20px;
 text-align: center;
 border-radius: 50%;
 background-color:#b30000;
 border-style: solid;
 border-color: #ffffff #b30000;
 border-width: 15px;
 }
.side_btn_css:hover
{
width: 200px;
height: 85px;
font-size: 20px;
color: #fff;
line-height:20px;
text-align: center;
border-radius: 50%;
background-color:#0a4241;
border-style: solid;
border-color: #ffffff #008080;
border-width: 15px;
}

.side_btn_css_focus
{
width: 200px;
height: 85px;
font-size: 20px;
color: #fff;
line-height:20px;
text-align: center;
border-radius: 50%;
background-color:#3333ff;
border-style: solid;
border-color: #000000 ##3333ff;
border-width: 15px;
 }
 </style>
<div id="left_buttons" style="size: auto;">
<asp:Button ID="bt_home1"   runat="server"   CssClass="side_btn_css"  text="Home1" Font-Size="Larger" onclick="bt_home1_Click"/> <p />
<asp:Button ID="bt_home2"  runat="server"   text="Home2" CssClass="side_btn_css"  Font-Size="Larger" onclick="bt_home2_Click" />
<p />
<asp:Button ID="bt_home3"  runat="server"  CssClass="side_btn_css"  text="Home3" Font-Size="Larger"  onclick="bt_home3_Click"/>  <p />
<asp:Button ID="bt_home4"  runat="server"   CssClass="side_btn_css"  text="Home4" Font-Size="Larger" onclick="bt_home4_Click"/></div>

protected void bt_home1_Click(object sender, EventArgs e)
{
 Response.Redirect("home1.aspx");  
}
protected void bt_home2_Click(object sender, EventArgs e)
{
 Response.Redirect("home2.aspx");  
}

Answer №1

To enhance your coding experience, consider incorporating Jquery into your webpage. While JavaScript can also achieve similar results, using Jquery is a more straightforward approach.

In order to dynamically add classes to buttons based on the requested page, extract the page name from the URL and create a JQuery selector accordingly.

$( document ).ready(function() {
    var page = url.split('/'); 
    page = page[page.length-1].replace(".aspx","");
    $("#bt_"+page).addClass("side_btn_css_focus");
});

You may also customize the text for both the side menu and top menu as needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing jQuery for JSON parsing

Within my JavaScript code, I am working with the following array: var versions = [{"id":"454","name":"jack"}, {"id":"4","name":"rose"} {"id":"6","name":"ikma"} {"id":"5","name":"naki"} {"id":"667","name":"dasi"} ] I need to extract the name from this ar ...

Utilizing CSS flexbox to occupy the remaining vertical space

I'm facing a scenario where I have three elements: div with content 1, div with content 2, and an image that spans 100% width (with variable height). My goal is to align div 1 at the top, the image at the bottom, and fill the remaining space with cont ...

Generate an array of checked inputs to be used when posting to a REST API

I have been using .push() to create a checked array of "List" inputs for posting to a REST API. However, it doesn't seem to be working correctly. When unchecking an item, it is not automatically removed from the array. Does anyone have a better solut ...

Creating a unique dimming effect for modals in a React application

Could someone assist me in adding opacity or dimming the background while a modal is open using the code provided? You can view the working example here. ...

Error: content within v-html directive not displaying as expected

The v-html content is not rendering correctly for me. Interestingly, when I remove the v-html in the first list item, it works fine. Take a look at my code below: <div> <br> <li v-html="`a`"> <ul> <li ...

Simulating NextJS router triggers using Jest

I've been attempting to simulate NextJS router events using Jest. I came across a useful resource at NextJS router & Jest. The approach outlined there closely resembles mine. Unfortunately, the solution provided in that post is not yielding the d ...

Tips for inserting line breaks within a <p> element in a contentEditable division

When I press enter or shift+enter on my contentEditable div, the new line is shown as a textNode within the div. However, I prefer the new line to be inside a p element. Seeking a straightforward solution Utilizing React Js, I store the content of the co ...

Error code 400 encountered during an HTTP POST request - issue stems from incorrect design of views and serializers

I keep encountering the following error: POST http://127.0.0.1:8000/api/creator_signup/ 400 (Bad Request) Every time I try to send data from my AngularJS application to my Django backend. When making a POST request, I used the following code (https://i. ...

Retrieving the output from within an AJAX function

I am trying to access the return value of the "res" variable from the function but it returns undefined. How can I solve this issue? function getResult() { var url = "https://translate.yandex.net/api/v1.5/tr.json/translate", keyAPI = "abcdefgh" ...

Modifying the href in Django according to the current page URL: a step-by-step guide

Like the title suggests, I'm curious about the proper way to dynamically change a link's href based on the current URL that the user is visiting. I attempted a solution, but it proved unsuccessful. {% if url == '' %} href='/cooki ...

What could possibly be the reason for this not returning null?

Consider this JavaScript snippet: var value = parseInt(""); console.log(value != Number.NaN ? value : null); Why does the console output Nan instead of null? Is there a way to modify the code so that it actually returns a null value? I attempted to wra ...

Implement seamless content loading using jQuery, eliminating the need

Is there a reason why this piece of code isn't working for me? I'm trying to load HTML content using jQuery and followed the instructions from this tutorial: Here's how my HTML looks: <div id="icon"> <a href="http://localhost/ ...

In development, Next.js dynamic routes function correctly, but in production they are displaying a 404 error page

I am currently working on implementing dynamic routes in my Next.js project to render pages based on user input. I have set up a route that should display the page content along with the id extracted from the URL using the useRouter() hook. Everything is f ...

Having trouble with Tailwind CSS not functioning correctly once the font is imported?

I am currently working on a next.js project and utilizing tailwind for styling. I have noticed an odd behavior when importing a custom font into my globals.css file. page.jsx "use client"; import React from "react"; const page = () = ...

Dealing with Javascript exceptions and sending email notifications in Django

I appreciate the traditional method of handling server-side exceptions in Django using Python. I am interested in finding a similar approach for client-side exception handling in JavaScript. So far, I have come across only one option which is DamnIT, but ...

The use of pattern fill in fabric.js is causing a decrease in rendering speed

I recently attempted to create a clip mask effect on a large image by using the picture as a pattern and setting it to the svg paths that support the desired shape. You can view the slow-loading jsfiddle example here: http://jsfiddle.net/minzojian/xwurbw ...

Deactivating the class from a button

On my website, I have 3 buttons that represent different product categories. The initial state of the page should load with the "All Products" button having an active class. However, when clicked, this active class should be removed from the "All Products" ...

I'm encountering difficulties with customizing the root styling of material-ui's DialogActions

Check out the two buttons in a DialogActions just like this. This is the JSX snippet I'm working with: <DialogActions classes={{ root: classes.dialogActionsLeft }}> <Button autoFocus onClick={() => { setOpen(false); }} ...

The particular division is failing to display in its designated location

This is quite an interesting predicament I am facing! Currently, I am in the process of coding a website and incorporating the three.js flocking birds animation on a specific div labeled 'canvas-div'. My intention is to have this animation displa ...

Protractor test freezes after attempting to click on an element

I have encountered a challenge while attempting to write a protractor test that selects an item from a custom dropdown menu. The issue arises when trying to click on an element other than the last one in the list, as it hangs and times out. Interestingly, ...