In modal popup - Server side validation work but popup is closed after message showing.
how to solve this.
and in jquery - i entered numeric value in text box and compare both the text box value, but not working
In modal popup - Server side validation work but popup is closed after message showing.
how to solve this.
and in jquery - i entered numeric value in text box and compare both the text box value, but not working
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 8, 2024, 2:29 AM EST
For the modal popup issue, you can prevent the modal from closing if there are validation errors. Here’s a general approach:
OkControlIDor anOnOkScripton the ModalPopupExtender. This will ensure that the ModalPopupExtender doesn’t close automatically when the “OK” button is clicked1.Here’s a sample jQuery code snippet for your reference:
$("#frmSendMessage").submit(function () { Recipient = $("input[name='recipient']").val(); MessageSubject = $("input[name='messageSubject']").val(); MessageBody = $("input[name='messageBody']").val(); return false; });This code prevents the modal from closing but it doesn’t show any of the errors4.
For the jQuery issue, you can compare numeric values in text boxes by parsing them as integers first. Here’s a sample code snippet:
$('.check').click(function () { var number1 = parseInt($('.number1').text()); var number2 = parseInt($('.number2').text()); if (number1 === number2) { $('.test').css ... } });This code compares two numbers correctly in jQuery5. Make sure you’re not comparing string representations of numbers, as that could lead to unexpected results.
Remember to replace the class names and variable names with the ones you’re using in your project. If you’re still facing issues, please provide more details or share the relevant parts of your code.
Thanks
rupesh gourRank #6,510 · 264 reputationPosted Jan 8, 2024, 2:33 AM EST
my popup is this
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 8, 2024, 2:37 AM EST
I see that you’re using Bootstrap’s modal component. If you want to prevent the modal from closing when server-side validation fails, you can stop the form submission and show the validation errors in the modal.
Here’s a sample approach:
$("#yourForm").submit(function (e) { e.preventDefault(); // Prevent form submission // Perform your validation here var isValid = ...; // Set this based on your validation if (isValid) { // If validation passes, submit the form manually this.submit(); } else { // If validation fails, show the modal with the error messages ShowPopup('Validation Error', 'Your error message here'); } });In this code, replace
#yourFormwith the id of your form, and replace the...invar isValid = ...;with your validation logic. TheShowPopupfunction is used to display the modal with the validation error messages.For the jQuery issue, you can compare numeric values in text boxes by parsing them as integers first. Here’s a sample code snippet:
$('.check').click(function () { var number1 = parseInt($('.number1').val(), 10); var number2 = parseInt($('.number2').val(), 10); if (number1 === number2) { // Do something when the numbers are equal } else { // Do something when the numbers are not equal } });In this code, replace
.check,.number1, and.number2with the appropriate selectors for your elements. TheparseIntfunction is used to convert the text box values to integers for comparison.Remember to replace the class names and variable names with the ones you’re using in your project. If you’re still facing issues, please provide more details or share the relevant parts of your code.
Sachin SinghRank #66 · 26.2K reputationPosted Jan 8, 2024, 3:25 AM EST
On your Ajax call, you must be getting the success message from server-side code on Ajax success, based on that close the modal,
if not getting anything from server then modify your server code to return some message.
$ajax({ //other props, success: function(res) { if(res.Message=="Success") { $("#ModalID").modal('close'); } } })