I need to disable the submit button, to prevent double posting.
I added the following attributes to the asp:button:
UseSubmitBehaviour="false"
OnClientClick="this.disabled='true';this.value='Please wait ...'"
This works only if on the first click all controls of the form are valid. But if any one of the asp:RequiredFieldValidor fails, the button is disabled until the page is refreshed.
Use the below code:
OnClientClick="if (Page_ClientValidate()) { this.disabled='true';this.value='Please wait ...'}"
Explanation
Page_ClientValidate() This method is used for asp.net client side validation. So, if you page in client side validated then only disable your text box.
Related
I have a custom validator and some other validators on the page. But whenever I click the submit button for first time it only fires the custom validator and when I click the button for second time it's validating rest of the validators. Please let me know if you have any solution.
Thanks
Check your Page_Load to make sure you are not hiding or enabling something after the second call. I had a similar problem before and it confused the heck out of me until I realized I was manipulating a Panel in the Page_Load that contained the validator.
Other than that, you would need to post code (your Page_Load and Click event).
On Client Side when
OnClientClick="return SomeCustomClientCode();"
Is called, asp.net validators e.g required field validators are disabled and it does not gets listed in validators collection and does not validate the field validated by this validator and page post backs if custom validation passes.
To avoid this explicitly enable asp.net validators in Custom validation code or else where so that it gets activated before page postback or in the begiining of custom validation as follows:
ValidatorEnable(document.getElementById('<%=rfvDDLStatus.ClientID%>'), true);
rfvDDLStatus ==> required field validator which was not firing.. ValidatorEnable ==> Client API to enable asp.net validator
I have two asp.net buttons in my page.If i make button cause validation false then am able to
fire button click event on server side but not able to validate text box values(but i need to validate text boxes) using required field validator.
Thank you very much...
If you want your form to be validated, you need CausesValidation to be true.
For the server side event handler to run, the form needs to be valid, according to the validators you have setup.
Can you post the page markup (including validators), so we can see the issue?
I'm using the ASP.NET login control and I'm displaying a jQuery throbber when the submit button is clicked. This works fine, but the throbber is visible if client side validation fails and the button is invisible, so the user cannot re-submit the form. How do I hide the throbber if client side validation fails?
Without knowing much about the detail... why don't you only start the throbber when the client side validation passes? As a user I'd be surprised to see a UI element flash up very temporarily, only to be removed again and replaced by an error message.
It was a little tricky but I got this working. First of all, the Login control must be templated, which I expected, but even so the ClientID of the button is inaccessible so I had to add a class selector to it. I first tried to add the throbber and turn it on if validation succeeded using the lightly/un documented Page_ClientValidate() event but that didn't work because the throbber by default subscribes to the button's click event and turns on before validation occurs.
What did work was sticking to the mini API and adding the throbber to the button if Page_IsValid is true. The button's CausesValidation attribute must be true (the default).
javascript:
$(document).ready(function() {
$('.login').click(function() {
if (Page_IsValid) {
$('.login').throbber({ image: "Images/throbber.gif" });
}
});
});
button markup; the only addition from the Login control template is the CssClass attribute:
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="uxLogin" CssClass="login" />
I have an aspx page in which i have 3 asp.net text boxes and 1 asp.net button control.I want to do a client side validation before the post back happens when i click on the button . ie ; If the the page passes the validation check,then only i need to invoke the server side button click event.Can any one help me ? Thanks in advance
Define JS function:
function validate(){
//perform some validation
return $("#myTextbox").val()=="";
}
call it on button control onclick event="return DoValidation();"
If JS function will return false, postback will be canceled.
If you want to integrate with ASP.net validation, need to register your Javascript validator using RegisterValidator declaration.
Don't forget to valiate on the server-side too, as Javascript may be disabled.
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();"