Controlling Button Enablement in ASP.NET C# Code-Behind and JavaScript

Looking for some assistance with enabling and disabling buttons based on two functions. The first function is a JavaScript function, while the second function triggers on another button click event. Currently, the buttons work as expected initially - Save button enabled and Register button disabled when the JavaScript function runs, then vice versa during the button click event. However, my issue arises during subsequent calls of the JavaScript function, where the previously set button states do not change. Any help or guidance on this would be greatly appreciated.

HTML:

<script type="text/javascript">
function exists()
{
    document.getElementById("<%= but_Register.ClientID %>").style.visibility = "hidden";
    document.getElementById("<%= btn_save.ClientID %>").style.visibility = "";
}
</script>

C# :

protected void btn_newrgstr_Click(object sender, EventArgs e)
{
    but_Register.Visible = true;
    btn_save.Visible = false;
}

Answer №1

It appears that in your code, you are toggling the visibility of buttons rather than enabling/disabling them. The client-side javascript function exists handles button visibility on the client side, while the server-side function btn_newrgstr_Click controls whether or not the button is rendered to the client. This can cause issues if the client-side function is unable to locate the button. One solution is to avoid using xxx.Visible = false on the server side and instead manipulate the control's style.

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

What is the best method for utilizing 2 SQL commands while only using one reader?

Is it possible to remove a Token from an SQL Database after it has been utilized? MySqlCommand cmdSel = new MySqlCommand("SELECT * FROM tokens WHERE token = " + int.Parse(passbox.Text), dbCon); MySqlDataReader dbRead = cmdSel.Execu ...

Is it achievable to pivot the outcome of a pivot query using sql or C#?

Here is a table with columns: https://i.sstatic.net/UNtRN.png I am looking to generate a report like this: https://i.sstatic.net/Iad3R.png I need to generate a report based on specific dates and products within those dates, cumulatively sorted by emplo ...

Discovering the culprit causing a freeze on your page: Uncovering the tool or technique to identify the problematic

What is the best tool to identify resource-heavy or infinite loop JavaScript/jQuery scripts? I am currently experiencing issues with a specific template: When I open this page on Firefox 46.0.1, it freezes after a few minutes. I am having trouble pinpoin ...

Reorganizing Arrays in Javascript: A How-To Guide

I have an array in JavaScript called var rows. [ { email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81f4f2e4f3b0c1e4f9e0ecf1ede4afe2eeec">[email protected]</a>' }, { email: '<a hre ...

Automating SQL quoting and line breaks

There are times when I have TSQL from SSMS that needs to be used in c# .NET Adding the " and Environment.NewLine can be quite time-consuming I wonder if there is a tool or macro available to automate this formatting? TSQL raw select * from hmAdjus ...

Pass a variable value as a parameter to a jQuery function using code-behind

Within my code behind, I am retrieving the [IDphoto] from an SQL database. My goal now is to pass this IDphoto as a parameter to a jQuery function upon onClick. How can I achieve this? Code behind sb.AppendFormat("<a onclick='popup()' href=& ...

Retrieving the source code created by ASPX and ASCX files

Have you ever experienced debugging an error that originates from an ASPX or ASCX file, where ASP.NET displays an error page revealing the source file and the line of code causing the issue? The displayed source file is generated through parsing the page/c ...

A guide on incorporating user input and output in Javascript using React and Material UI

Currently, I am working on a project that requires ReactJS and Material UI. My main goal is to implement the code provided below in just a single JS file. Is there a way to modify this code to meet my formatting requirements? //js file function calculat ...

How can I make child events affect the state of the parent component in ReactJs?

I have developed a menu component in reactjs. The parent component includes a method called "handleClick" which controls the opening and closing of the menu by toggling its "open state". Now, I am attempting to pass a click event from the child component ...

Preventing postback in timer control implementation

I am currently working on a project that requires me to display both the date and a timer. Here is the code snippet I have been using: <asp:ScriptManager ID="sc2" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="up1" runat="server" ...

Sort a List Based on Various Requirements

My goal is to apply filters to the array below: const array = [{city: "Fullerton", techName: ["Sean"], routeName: ["Route 1"], routeDay: "Monday"}, {city: "Long Beach", techName: ["Sean", "Greg"], routeName: ["Route 1", "Route 3"], routeDay: "Monday"}, ...

End the streaming process in React Native using React Navigation

Currently, I am developing an application with two distinct streams (A and B) that can both be accessed from the home screen. However, I have encountered a persistent issue. Whenever I enter stream A, everything functions as expected. But when I try to ac ...

Error encountered: Denied access in AWS Transcription Node JS API

I have been working with the AWS transcription API in Node JS and my code looks like this: const tClient = new TranscribeClient({ region: "us-east-1", credentials: { accessKeyId: AWS_ID, secretAccessKey: SECRET, ...

Is it possible for Ajax to actually make GET requests to the server, and if it does, why doesn't it appear in Firebug?

I have a LAMP setup on my Ubuntu and I am attempting to use Ajax to print the output in an unordered list. However, I am not seeing any results and there are no server calls showing up in Firebug. Here is the HTML file where the call is made: <!DOCTYP ...

What is the method to check for the absence of an anchor element in jest and react-testing-library?

In my React component, a link is rendered based on a specific rule. The markup looks like this when there is a link within the h4 element: <h4><a href="">foo</a></h4> <p>blah blah <a href="">bar</ ...

Creating an Image Slideshow on Your Website

I'm looking to create an image slideshow on my website that functions similarly to the one found at . However, I want the images to occupy the entire screen rather than having smaller images like the reference site. Can anyone offer guidance on how t ...

The IIS URL rewrite is causing issues with the rewriting of CSS and JS files

Struggling with my URL rewrites - every time I set up a rewrite for a page, it ends up affecting the CSS and JS files linked within the webpage, resulting in them not displaying properly. In an attempt to fix this issue, I tried using fully qualified path ...

Requiring addresses for Google Maps in order to display directions

To display the directions between two addresses based on the chosen transportation mode, I need to pass the addresses to the code in page 2. After the user selects two cities from a Dropdown box on page 1, they will be sent to the code to show their locati ...

Use two queries to apply filters to entries in NextJS

Greetings to all! I am currently working on a project in NextJS that involves showcasing a portfolio of works generated from JSON data. [ { "title": "WordPress Plugin for Yandex Recommender Widget", "image" ...

How to manage null data from a query when working with a listbox

When choosing a value from the first listbox, the second listbox is populated accordingly. However, there are instances where the selected value from the first listbox does not return any data. In such cases, I would like to display a message on the scre ...