hi,
need technical suggestion required.
we have 4 buttons in screen each button performing different services
button1, button2, button3, button4
when user press button1 its hitting API and doing some function.
meanwhile if user clicks again its throwing exception since calling twice of that API
throwing exception since calling the third party services.
so expecting to intimate the user to wait in the form of message..
suppose if user clicks button1 and before its returns the solution he may clicks the other buttons that time also need to inform the user as some action is in progress.
kindly suggest me any solutions.
am just thinking to create a hidden variable and store some value on click of any button ..
before processing API if this hidden variable having any value then throw a message to user.
Naimish MakwanaPosted Jan 8, 2024, 4:50 AM
Sure, I can suggest a solution using jQuery and .NET MVC. You can disable all buttons when an API call is in progress and enable them once the API call is complete. Here’s a simple way to do it:
In your .NET MVC Controller:
This way, when a user clicks any button, all buttons will be disabled until the API call is complete, preventing multiple API calls at the same time. You can also add a loading spinner or a message to let the user know that an action is in progress. Remember to handle exceptions properly in your API calls.
Thanks
Anandu G NathPosted Jan 8, 2024, 10:26 AM
Hai Murali P ,
You can disable the button after the first button click , once the function successfully completed you can enable it aagain.
Tuhin PaulPosted Jan 8, 2024, 9:51 AM
you can implement a solution to handle multiple button clicks and inform the user about the ongoing process. Your idea of using a hidden variable is a good approach.
Jayraj ChhayaPosted Jan 8, 2024, 6:10 AM
To handle multiple button clicks and API calls in Dot Net, you can implement a solution that prevents multiple API calls and informs the user about the ongoing action. Here's a suggestion:
Create a hidden variable, let's call it
isProcessing, and initialize it asfalsewhen the page loads.When a button is clicked, check the value of
isProcessing. If it istrue, display a message to the user indicating that an action is already in progress. If it isfalse, proceed with the API call.Before making the API call, set
isProcessingtotrueto indicate that an action is in progress.Once the API call returns, set
isProcessingback tofalseto allow subsequent button clicks.Here's an example of how you can implement this in C#:
You can apply the same logic to the other buttons as well. By using the
isProcessingvariable, you can prevent multiple API calls and inform the user about ongoing actions.Naimish MakwanaPosted Jan 8, 2024, 5:23 AM
Understood. If you can’t disable the buttons, you can use a flag to check if an API call is in progress. Here’s how you can do it:
In your .NET MVC Controller:
This way, when a user clicks any button while an API call is in progress, they will see an alert message and the API call won’t be triggered. Once the API call is complete, the flag is set to false and the user can trigger another API call. Remember to handle exceptions properly in your API calls.
Murali PPosted Jan 8, 2024, 5:19 AM
As per requirement we should not disable buttons.