views:

126

answers:

2

I have a form which is sent to an email address when user clicks Send. The form is validated first. I want to show 'Please wait' text to the user when he clicks the button. Now 'Please wait' text shows fine if the form fields are valid and the form is sent normally. But if there is an error in the form fields the 'Please wait' text still shows and I don't want that.

Now I'm using JavaScript, here the script:

<script language="javascript" type="text/javascript">
    function showPleaseWait()
    {
        document.getElementById('PleaseWait').style.display = 'block';
    }
</script>

Here is Send button (uses onMouseDown) and PleaseWait div (which is shown):

<asp:Button ID="btnSend" runat="server" Text="Send Order" Enabled="true" ValidationGroup="Validate" onMouseDown="showPleaseWait()" CausesValidation="false" />

<div id="PleaseWait" style="display: none;">Sending, please wait.</div>

I'm trying to get into the validation first and if it passes ok, then show the Please Wait text. It doesn't work if I try to show the PleaseWait div in the beginning of btnSend. How should I do this?

Many thanks for your help!

+1  A: 

Call Page_ClientValidate(). It returns true if the page was valid. If you are using ASP.NET 2.0, pass the validation group name as a parameter (Page_ClientValidate("") will handle when there is no group name.)

Steav
I added Page_ClientValidate() into JavaScript function and now it's working just like I wanted! Many thanks!function showPleaseWait() { if (Page_ClientValidate('Pakollinen')) { document.getElementById('PleaseWait').style.display = 'block'; } }
Lillie
A: 

Steav is correct in assertion. However, if you are using ASP.NET AJAX you could look at using the UpdateProgress control as an alternative to "hand rolling" your 'please wait' alerts.

Dan Diplo