Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

asp.net - Page_ClientValidate is validating multiple times.

problem i have is that, the validation summary message(alert) is displayed twice. I cannot figure out the reason.

Please help. Here is the code

function validate() //javascript function
{
    if (typeof(Page_ClientValidate) == 'function') 
    {
        var isPageValid = Page_ClientValidate();
        if(isPageValid)
        {
        }
    }
}

<asp:Button ID="btn1" runat="server" OnClientClick="validate()" Text="button"
                    ValidationGroup="ContactGroup" />

<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" 
                    ShowMessageBox="true" ShowSummary="false" ValidationGroup="ContactGroup" />
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem is that the function Page_ClientValidate takes an input parameter, if you don't specify the input then the validationsummary triggers once per groupname.

In your case, the function triggers twice: once for groupname="ContactGroup" and another time for groupname=""

you should change

var isPageValid = Page_ClientValidate();

to

var isPageValid = Page_ClientValidate('');

if you don't want to specify a ValidationGroup, or if you want to specify a groupname then you need to call Page_ClientValidate like so:

var isPageValid = Page_ClientValidate('ContactGroup');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...