开发者

Showing 'Please wait' message, not when there is an error in the validation

开发者 https://www.devze.com 2022-12-27 07:31 出处:网络
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

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">
    func开发者_运维百科tion 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!


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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消