Utilize a CompareValidator to evaluate conditions only when necessary

I am dealing with a checkbox containing a javascript function that triggers onclick to toggle the visibility of a div. Within this div, there is a textbox with a CompareValidator that validates the input as a Double. The issue arises when the checkbox is checked and the div is shown, causing the CompareValidator to validate an empty textbox, resulting in an error message display by default. Is there a way to modify the CompareValidator so that it only validates when the text in the textbox is not null or an empty string after the checkbox has made the div visible? Thank you for your help.

        <table id="tblLabTests" class="fullWidth dataEntryTableTop" runat="server" visible="false" clientidmode="Static">
            <tr id="trL_FBC" clientidmode="static">
                <td>
                    <asp:CheckBox ID="chkL_FBC" runat="server" clientidmode="static" />
                    <asp:Label AssociatedControlID="chkL_FBC" ID="lblL_FBC" runat="server" Text="FBC" />
                </td>
                <td>
                    <div id="divFBC" runat="server" clientidmode="static">
                        <table id="tblFBC" class="fullWidth noBorder" runat="server" clientidmode="static">
                            <tr>
                                <td>
                                    <asp:Label ID="lblPlateletCount" runat="server" Text="Platelet Count" />
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPlateletCount" runat="server" MaxLength="4" CssClass="width50" />                                        
                                    <asp:Label ID="Label10" runat="server">*10<sup>9</sup>/L</asp:Label><br />
                                    <asp:CompareValidator ClientIDMode="Static" CssClass="cvRed" runat="server" id="CompareValidator1" ControlToValidate="txtPlateletCount" Type="Double" ErrorMessage="Must be a number" Display="Dynamic" Operator="DataTypeCheck" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>


        function fbcUpdate() {
            var checked = $('#chkL_FBC').is(':checked');
            if (checked) {
                $('#divFBC').css('display', '');
            }
            else {
                $('#divFBC').css('display', 'none');
            }
        }

Answer №1

Apologies, I've decided to move on from this approach. I have incorporated validation into the entity using Entity Framework in the code behind. Appreciate your understanding.

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

Issues with Laravel 5.8 and Bootstrap not functioning properly in Jquery

Check out this link for using Bootstrap Select. The code works perfectly in the view, but when I try to implement it with jQuery below, it doesn't work. Can someone help me fix this issue? View Code: <table id="tableAppointment" style=&q ...

Exploring the growth of CSS offsetting alongside with AngularJS

I am working on an Angular app where I need to increase the left offset of a div by 90px every time the slideThis() function is called. In jQuery, I would typically achieve this using left: '+=90', but I'm struggling to find a similar method ...

Dividing a JSON array by a specific key using lodash underscore

I'm on a quest to extract the distinct items in every column of a JSON array. Here is what I aim to convert : var items = [ {"name": "Type 1","id": 13}, {"name": "Type 2","id": 14}, {"name": "Type 3","id": 14}, {"name": "Type 3","id": 13}, {"na ...

Sending a document through the input field with React Hook Form

In my application, I have implemented a file input to submit a file and send it to a firebase storage bucket. To achieve this functionality, I am utilizing the react-hook-form library. However, I encountered an issue - I wanted the file to be uploaded with ...

Tips for seamlessly placing a div with a background image within a parent container, all while preventing any scrolling issues as the child div rotates

I created a simple demo featuring a square image with rounded corners to give it a circular appearance. The image rotates slowly, but as it moves diagonally, the horizontal width fluctuates, causing the parent container to resize. I want the parent contain ...

Tips on retrieving an input value from a dynamic list

I am struggling to retrieve the correct value with JavaScript as it always shows me the first input value. Any help would be greatly appreciated! Thank you in advance! <html> <head> </head> <body> <?php while($i < $forid){ ...

Is it possible to deactivate an anchor tag based on the result of a conditional statement that returns a string?

I've created an anchor tag (not a button) with text that redirects me to another page <StyledTableCell align="center"> <Link href={`/races/results/${race.id}`}>{race.race_name}</Link> </StyledTableCell> There is a ...

Using Selenium with Node.js to dynamically switch to a newly created tab

If there is only one tab open, the newest tab will always be positioned as the last tab. This rule also applies when the last tab opens a new tab. The code snippet below will help in switching to the last tab. UPDATE: Credit goes to @JimEvans Many solut ...

Having trouble with Gulp hanging on the task named 'some_task_name' when using gulp.parallel or gulp.series?

Out of the blue, my gulp configuration suddenly stopped working. It gets stuck on 'Starting...' when I use tasks with gulp.parallel or gulp.series. Just yesterday, the same config was running smoothly. Why did this sudden change occur? Here is a ...

Having trouble getting the background of the <span> element to function properly

So, here is the code I have been working on: echo "<span style='float:right; text-align:right; background-image:url('" . $icon_url . "') no-repeat top right; height:86px; width:86px; display:block;'>" . $curr_temp . "<br /> ...

Dynamic JavaScript tool

Does anyone know which library is being used on the website linked here? I am working on a project similar to this and would appreciate if anyone can identify this library for me. Thank you in advance. ...

Tips for efficiently loading large amounts of HTML data using jQuery AJAX as needed

Recently, I completed the development of our company's website where each product detail is displayed in one record on an ASPX page. Sometimes, the HTML data is extensive, requiring users to scroll multiple times to read the content in its entirety. I ...

The site is visually appealing in Firefox, but has a few issues on Chrome

I've encountered a common issue where my website displays perfectly in Firefox but looks terrible in Dreamweaver and Chrome. To fix it, I made live CSS edits in Firefox then copied them to Dreamweaver resulting in a mess. Here's how it should lo ...

How can I trigger a PHP function from within an HTML onClick() event?

While I have come across a response on stackoverflow regarding form submission, my query pertains to a different implementation. I am in need of calling a function that registers a variable in $_SESSION[], and then redirects to another page (html/php). I ...

Exploring the depths of nested arrays and updating with mongoose

Here is a simplified diagram of a document in my Model: { ar1: [ { b: { ar2: [{ _id: 1, value: 2 }], }, }, { b: { ar2: [{ _id: 2, value: 2 }], }, ...

Having trouble with an onClick function not working on a .php webpage?

I recently developed a simple JavaScript script that dynamically loads an image based on user input in a text field (e.g., entering 'brick1' loads brick1.jpg). Although this works fine on a regular HTML page, I faced issues triggering the onClick ...

Guide on utilizing every array value during each iteration of a for loop, ensuring that the same number of values

Below is the equipos_seleccionados array: ["12 - v4", "100 - v500"] This is a preview of the frontend: https://i.sstatic.net/nJU9d.png When you input values in the head section, textboxes are generated automatically. Objective: Assi ...

Inserting a crisp white divider between items in breadcrumb navigation in the form of arrowheads

I have designed a unique custom breadcrumb with an arrow shape : <ol class="breadcrumb-arrow"> <li class="active"><a href="#">1. Foo<span class="arrow"></span></a> </li> <li ...

What is the best way to transmit a two-dimensional array using ajax?

Here is the process I use to send data to the server: var points = []; var coords = polyline.geometry.getCoordinates(); for (var i = 0; i < coords.length; i++) { var x = (coords[i][0]).toFixed(4); var y = (coords[i][1]).toFixed(4); points[i ...

Unable to retrieve data function properties within Vue.Js Component methods

Looking for some help with setting up a welcome message using an input field in Vue.js. I am trying to store the username in a data property called username: ''. However, when I attempt to access it within the methods, I receive an error stating ...