Tips for changing CSS properties based on certain conditions

Here is a RadioButton list that I'm working with:

<asp:Panel ID="pnl_select_sign" runat="server" Visible="false" Style="text-align: right">
        <asp:RadioButtonList ID="rb_select_sign" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
            OnSelectedIndexChanged="rb_select_sign_SelectedIndexChanged" CausesValidation="false"
            AppendDataBoundItems="true">
            <asp:ListItem Selected="True" Value="0">Normal</asp:ListItem>
            <asp:ListItem Value="1">Electronic</asp:ListItem>
        </asp:RadioButtonList>
    </asp:Panel>

I am looking to update the overflow-y CSS property.

Change overflow-y :auto; to overflow-y :hidden;

This change should be applied to the div with id = wrap_form

When selecting the ListItem with Value = 1;


Output from FireBug:

<td>
<input id="ctl00_ContentPlaceHolder1_rb_select_sign_0" type="radio" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$rb_select_sign$0\',\'\')', 0)" value="0" name="ctl00$ContentPlaceHolder1$rb_select_sign">
<label for="ctl00_ContentPlaceHolder1_rb_select_sign_0">Normal</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder1_rb_select_sign_1" type="radio" checked="checked" value="1" name="ctl00$ContentPlaceHolder1$rb_select_sign">
<label for="ctl00_ContentPlaceHolder1_rb_select_sign_1">Electronic</label>
</td>

Answer №1

Remember that by using the recommended JavaScript solutions, the CSS will revert to its original state after a page postback. Since you are already utilizing a postback for your RadioButtonList, it might be more effective to adjust the style server-side instead.

Update

Include this snippet in the method that handles changes in item selection within the list:

protected void rb_select_sign_SelectedIndexChanged(object sender, EventArgs e)
{
    if (rb_select_sign.SelectedValue == "1")
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "styleChangeScript", "<script type='text/javascript'>var divToChange = document.getElementById('wrap_form'); if(divToChange) { divToChange.style.overflowY = 'hidden' }</script>", false);
    }
    // The remaining portion of the original code for this method should be placed here
    //...
}

To ensure functionality even when triggering other buttons or events causing postbacks, consider placing the same set of code lines within the Page_Load event of your page (or create a separate method and invoke it from both locations).

Answer №2

Here is an example of how you can achieve this:

$('input[id^="ctl00_"]').click(function() {
 if ($(this).val() == 1) {
  $('#wrap_form').css('overflow-y', 'hidden');
 }
})

You can also view the code on jsfiddle

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 Angularjs for dynamic data binding in HTML attributes and style declarations

Can someone help me figure out how to use an AngularJS model as the value for an HTML attribute? For example: <div ng-controller="deviceWidth" width={{width}}> </div> Additionally, how can I achieve this within <style> markup? Where ...

Creating customized headers using $.ajax for JSONP or JSON requests

Having trouble sending custom headers with a jQuery ajax JSON (or JSONP) request. Here's the code I'm using: $.ajax({ beforeSend: function(xhr) { xhr.setRequestHeader("X-VER", VER); xhr.setRequestHeader("X-TIMESTAMP", ...

Merging sort and uniq functionalities to create a single function in JavaScript

I've been working with the sortBy and uniqBy functions, but I find myself iterating over the array twice when using the combined sortUniqBy. If you want to check out the code, feel free to click on this link to the codesandbox. Here's a snippet o ...

Ways to ensure the image stays fixed even as the screen dimensions fluctuate. HTML/CSS

Struggling to create an HTML header with a title and image positioned on the right side, but facing issues with the image shifting over the title when screen size changes. How can I ensure the image stays in place? Have tried various solutions without succ ...

In search of a dropline menu with a comparable style

My search for a menu like the one found on www.ultragraph.co.uk has been exhaustive. I have only come across simple dropline menus, but I am seeking one with hidden sub-menus that reveal upon mouseover similar to ultragraph.co.uk. If anyone has any sugge ...

Prevent regex from matching leading and trailing white spaces when validating email addresses with JavaScript

In my current setup, I utilize the following regular expression for email validation: /^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/ My attempt to validate the email is shown below: if (!event.target.value.match(/^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\. ...

Transitioning template engine from Razor (asp.net) to Angular JS for improved functionality

Our team has been utilizing ASP.NET Razor to generate HTML, incorporate partial views in layouts, and more. However, with the emergence of Angular and its strong capabilities, we are eager to transition towards using it extensively. A colleague proposed ...

Acquire the Information from a Textarea That Has Been Edited by the User

My challenge lies in taking user-entered text from a content editable textarea and sending it via POST request, but the fields edited by the user are returning with an empty textContent. The code snippet below shows that each .entryRow (obj) contains multi ...

Adjust the font color of the X and Y axis

Is there a way to customize the color of the X and Y axes labels in Chart.js? I attempted to use the fontColor property within scaleLabel, but I suspect I may be placing it incorrectly? I experimented with placing it under scale as suggested by the source ...

Conceal elements when they are too small without the use of JavaScript

I want to be able to hide content when the window size is below a certain point. After finding an example at (http://css-tricks.com/dynamic-page-replacing-content/), I still couldn't figure out why it actually works. <div class="container"> ...

The Nodejs express static directory is failing to serve certain files

Hello everyone, I'm currently working on a project using NodeJs, Express, and AngularJS. I've encountered an issue where my page is unable to locate certain JavaScript and CSS files in the public static folder, resulting in a 404 error. Strangely ...

Ways to conceal a column within columnSelection

Can anyone help me with setting the Column selection for Sender and Receiver in bootgrid without including Id in the column selection dropdown? I need some guidance on how to achieve this. Check out the image below for reference https://i.sstatic.net/4EEW ...

Dividing blocks of text into individual sentences

Seeking a solution to splitting a paragraph into individual sentences, I initially attempted the following code: var sentences = paragraph.split('.'); While this method was effective in most cases, it encountered issues with sentences like: ...

Having trouble with JSON/jQuery syntax?

I am attempting to populate a set of DIVs with image backgrounds by reading images from a specific folder. The jQuery code I have written is shown below: $.getJSON('../functions.php', function(images) { images.each( function() { $('#m ...

Is there a way to close the menu in react by clicking anywhere on the

Presently, I have a solution to close my topbar menu that involves clicking the menu icon. However, this method is not satisfactory because it only closes the menu when the icon is clicked. I am looking for a way to make the menu close when any area of th ...

Is it possible to use D3 for DOM manipulation instead of jQuery?

After experimenting with d3 recently, I noticed some similarities with jquery. Is it feasible to substitute d3 for jquery in terms of general dom management? This isn't a comparison question per se, but I'd appreciate insights on when it might b ...

Tips for updating a section of a webpage without the need to redirect to a different page: use technologies such as Express, Nodejs, and M

In the midst of developing a two-player game where one player must guess a word within 10 tries, I find myself facing a challenge. I need to display the player's guesses and scores in a table without refreshing the entire page. Unfortunately, my exper ...

unable to properly evaluate the string results from the AJAX request

Utilizing AJAX to verify a user's login information for accuracy, I am encountering an issue where the comparison between the returned "success" String and the expected value using == or === always results in failure. The AJAX implementation is as fo ...

Managing Arduino using a local webpage powered by node.js

Thank you for your patience as I navigate through this new experience. Recently, I wrote a basic python code to send information to an Arduino and control its servo: def main(inp): import serial ser = serial.Serial("/dev/cu.usbmodemfa131") # open ...

What exactly is the window object model all about?

While I understand that there is a concept known as the DOM in javascript, I have often wondered why there isn't something similar to a Window Object Model. After all, if you look at the structure of the DOM-tree, it does seem like it could be represe ...