I have asp.net ajax modal popup extender in which I have placed text boxes. The text boxes are validated and the validation error messages are shown.
There is a scenario where I need to clear the validation error messages.
When I save the modal popup without entering values, validation error messages appear. Now I close the modal popup clicking on cancel button.
Next time when I open the modal popup I see the same error messages. How could I clear just the validation error messages through jquery. I don't want to disable the validators but I only need to clear the error.
Via user10725000, who really deserves the credit:
I tried the bellow code and then it worked. Cheers!
$.each(Page_Validators, function (index, validator) {
$(validator).attr('style','display:none;')
});
Related
I have some input fields, regular expression validators, and custom validators inside an ASP.NET ASCX control. The behavior is a bit odd in that it works the following way:
If a client side validator flags an error message and I tab away from the input field and click submit then the page posts as it should. However, if a client side validator has flagged an error and instead I correct the error and click submit button then the error is cleared but the page is not submitted until I click the submit button a second time.
My question is how do I change this behavior such that I only need to click the submit button once to both clear the error and postback the page? Also, is this "behavior" standard?
Update: This behavior occurs without using the user control. I believe it is specific behavior to the CompareValidator. Nope, same behavior occurs with custom validator. If I don't "tab away" and click the button then I must click it twice to get the postback to occur. The first click just clears the validators.
The issue is that the CustomValidator has display type as Dynamic and not Static. This post helped me to discover the answer
RequiredFieldValidator have to click twice
I will give credit for anyone who explains why it causes this behavior.
I have a modal popup in my aspx file. i am doing a code validation in Javascript on click of a button inside the Javascript. When the validation is successful, the popup should close and when unsuccessful, it should display an alert message and retain the popup. How do I do this in Javascript?
I have a composite User control for entering dates:
The CustomValidator will include server sided validation code. I would like the error message to be cleared via client sided script if the user alters teh date value in any way. To do this, I included the following code to hook up the two drop downs and the year text box to the validation control:
<script type="text/javascript">
ValidatorHookupControlID("<%= ddlMonth.ClientID%>", document.getElementById("<%= CustomValidator1.ClientID%>"));
ValidatorHookupControlID("<%= ddlDate.ClientID%>", document.getElementById("<%= CustomValidator1.ClientID%>"));
ValidatorHookupControlID("<%= txtYear.ClientID%>", document.getElementById("<%= CustomValidator1.ClientID%>"));
</script>
However, I would also like the Validation error to be cleared when the user clicks the clear button. When the user clicks the Clear button, the other 3 controls are reset. To avoid a Post back, the Clear button is a regular HTML button with an OnClick event that resets the 3 controls. Unfortunately, the ValidatorHookupControlID method does not seem to work on HTML controls, so I thought to change the HTML Button to an ASP button and to Hookup to that control instead. However, I cannot seem to eliminate the Postback functionality associated by default with the ASP button control. I tried to set the UseSubmitBehavior to False, but it still submits. I tried to return false in my btnClear_OnClick client code, but the code sent to the browser included a DoPostback call after my call.
btnClear.Attributes.Add("onClick", "btnClear_OnClick();")
Instead of adding OnClick code, I tried overwriting it, but the DoPostBack code was still included in the final code that was sent to the browser.
What do I have to do to get the Clear button to clear the CustomValidator error when clicked and avoid a postback?
btnClear.Attributes.Item("onClick") = "btnClear_OnClick();"
Try adding a return false; at the end of your onClick call. That should prevent the default behavior (in this case submit).
btnClear.Attributes.Add("onClick", "btnClear_OnClick(); return false;")
Are you wanting to clear the error message on the client side if they fix the error without having to click on anything right?
I did something like this if I have your issue right but calling a revalidation function that called some client side javascript code and then hides the span that the error message is in if they fixed the issue.
See my blog article and let me know if this is what you are wanting to solve. The part you want to read is towards the bottom.
http://coding.infoconex.com/post/ASPNET-CustomValidator-that-validates-multiple-controls-using-both-Server-Side-and-Client-Side-scripting.aspx
I've a form with different field, a validation summary and a button Sign up!
When I click on Sign up, if a field is empty, it active validation summary and until here there's no problem.
So the problem is that I would want active a jQuery script after it was clicked Sign up button and it appeared validation summary.
I try with
$(this).load(function()
but in effect it occur when the page is load and not after the button is clicked.
I try also use button's onclick ,but I have to use script after onclick and not while.
I used Validation group for all field of form, also button and for this reason it seems doesn't postback!
Um your question is a bit unclear to me but wouldn't this work ?
$("#sign_btn").click(function(){
alert("I was clicked");
});
sign_btn is the ID of the button.
I have a little problem with the validation in one form
the form is composed by two taqs. There is a "Save" button in each tap (is the same control for both) and saves the form info. there are validation controls in one tab but not in the second. When we try to save the info from the second tab, and the info has not been filled in the first tab, the validators fire, and nothing happends, but because this validators are shown in the other tab, the end user might be thinking that the operation has been completed, instead, I would like to show a msgBox telling the user about the errors in the other tab. How do I know that the validators in the other tab have been fired, and display the error message when the button is clicked?
You should use the ValidationGroup of your validator controls and the appropriate submit button. You can also use a ValidationSummary control which displays a summary of the validation messages - this can be set to display a message box if you want by setting the property ShowMessageBox=true.
taqs - tap
dear why are you so confused?
All the validators are posted to the page as JavaScript functions. You can call the validation function on button's click and take the appropriate action.
You can use on buttons
onClientClick="Page_ClientValidate();"