This is a migrated thread and some comments may be shown as answers.

Single Click Button with RequiredFieldValidators

2 Answers 72 Views
Button
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 31 Aug 2011, 12:32 AM
Hi,

I'm using single click buttons.  What do I need to do for the client-side validators to fire before the button gets disabled?  The problem I'm having is my button is becoming disabled in the OnClientClicked, but my asp:RequiredFieldValidators are preventing the form from being submitted.  I only want the single click feature to kick in if all the client-side validation passes.

Thanks,
Mike

2 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 31 Aug 2011, 01:02 PM
Hello Mike,

Here is the logic I use for my single-click buttons, which takes validation into consideration (when it exists):

function btnSingleClick_OnClientClicked(sender, args) {
    try {
        // determine if page is valid
        var pageIsValid;
  
        try {
            // get value from Page_IsValid
            // NOTE: Contained this assignment in try block in case Page_IsValid doesn't exist
            pageIsValid = Page_IsValid;
        } catch (e) { }
  
        // make sure page is valid or validation is null (doesn't exist)
        if (pageIsValid || pageIsValid == null) {
            // disable control
            sender.set_enabled(false);
        }
    } catch (e) {
    }
}

I hope that helps.
0
Slav
Telerik team
answered on 31 Aug 2011, 04:01 PM
Hello Kevin,
 
In such scenarios you should ensure that the page validation is executed before the custom client-side scripts. This can be achieved by validating the aspx page on the client via the Page_ClientValidate method. Please check this help article in order to learn more on the matter: RadButton Validation And Client-Side Event Handlers.

Greetings,
Slav
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Button
Asked by
Mike
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Slav
Telerik team
Share this question
or