views:

3837

answers:

4

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.

A: 

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.

Richard L
the problem is not during the upload, but when the ValidationSummary control gives an error that the user has to correct. I need to know that there was an error and not show the "waiting" div
Arthur Chaparyan
+1  A: 

I think this will do what you want.

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

if(isValid)
{
   ShowMessage(...);
}
John MacIntyre
+1  A: 

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.

Arthur Chaparyan
A: 

I had a similar problem where i was showing ..updating please wait' message John MacIntyre's solution worked for me

mahesh