Question

Is there a way to check if a ValidationSummary control has its IsValid property set to true using Javascript in the OnClientClick event of a button?

What I'm trying to do is to show a message that says "please wait while your file is uploading" on an upload page, but if I use javascript to show that message, it shows up even when the ValidationSummary has errors, so the message shows up along with the errors underneath, which confuses users.

Was it helpful?

Solution 2

In case others need something like this, here is my solution:

In the button's OnClientClick event, I'm calling a javascript function called showContent(). In this function, I use setTimeout to call a second function that checks the page's IsValid property:

function showContent() 
{
    setTimeout("delayedShow()", 1);
}

function delayedShow() 
{
    if (Page_IsValid != null && Page_IsValid == true) 
    {
       document.getElementById('divUploading').style.display = "block";
    }
}

The Page_IsValid returns true in the OnClientClick event because the javascript validation runs after this, so the 1 second delay allows the IsValid property to be properly set.

OTHER TIPS

I think this will do what you want.

var isValid = false;
if (typeof(Page_ClientValidate) == 'function') 
{
   isValid = Page_ClientValidate();
}

if(isValid)
{
   ShowMessage(...);
}

If you have several validation groups on single page then you should check only certain group:

var isValid = Page_ClientValidate('GroupName');

I guess what you should do is dissable the uppload button and show a message while upload is in progress. For example by using an ajax panel and an progress template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top