Display in correct order using RequiredFieldValidators, ValidatorCallout and a ModalPopupExtender of validation is OK

强颜欢笑 提交于 2019-12-12 03:11:20

问题


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


回答1:


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" />



回答2:


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>


来源:https://stackoverflow.com/questions/9826141/display-in-correct-order-using-requiredfieldvalidators-validatorcallout-and-a-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!