Display in correct order using RequiredFieldValida

2019-08-22 17:11发布

I'm trying to get a sequence of things to happen in the correct order, but no luck. What I have is a number of fields with asp:ReuiredFieldValidators and asp:ValidatorCallout to display validation messages. This is triggered with a button Save with validation="true".

If all validates, it should display a modal dialog asking for two choises on how to save the data. No matter the answer, it should always continue at this stage to code behind save function.The AjaxToolkit_ModalPopupExtender is connected to the same save button.

What happens is that the validation callouts and modal dialog is shown at the same time.

Searched for tips and help but haven't found any, for me, helpful! Most grateful for any help!

Cheers /Johan

2条回答
Emotional °昔
2楼-- · 2019-08-22 17:53

You can show the ModalPopup from codebehind(in BtnSave.Click-handler) if the page is valid:

Page.Validate("YourValidationGroup");
If(Page.IsValid){ 
    ModalPopup1.Show();
}

Therefor you need to set the TargetControlID of the ModalPopupExtender to a hidden button:

<asp:Button ID="Hid_ShowDialog" Style="display: none" runat="server" />
查看更多
迷人小祖宗
3楼-- · 2019-08-22 17:56

You must move to Code Behind only when the Page is validated in client side. You can do it using OnClientClick of button

    <asp:Button ID="ShowDialog" onClientClick = "return ValidatePage();" 
     runat="server" />


    <script type="text/javascript">

    function ValidatePage() {

        if (typeof (Page_ClientValidate) == 'function') {
            Page_ClientValidate();
        }

        if (Page_IsValid) {
            // do something
            alert('Page is valid!');                
            return true;
        }
        else {
            // do something else
            alert('Page is not valid!');
            return false;
        }
    }

</script>
查看更多
登录 后发表回答