Javascript如果按下取消,确认没有停止发回的请求?

时间:2017-07-04 05:42:02

标签: javascript asp.net validation confirm requiredfieldvalidator

我正在使用带有confirm()消息框的Javascript函数,如果我在确认消息框上按下取消但是ValidatorGroup为true,那么它还有RequiredFieldValidator,那么它不会停止回复请求。

我想以这样的方式实现if if validatorGroup是treu但函数返回false然后请求不应该回发

这是我的代码: -

<asp:Button ID="btnStaffSendRequest" runat="server" Text="Send" OnClientClick="UploadRefrrel()"
                        UseSubmitBehavior="false" ValidationGroup="SaveRequestGroup" OnClick="btnStaffSendRequest_OnClick"
                        TabIndex="1000" />

这是我的Javascript功能: -

<script language="javascript" type="text/javascript">

                            function UploadRefrrel() {
                                var hiddenFile = this.document.getElementById("<%= hfInputForm.ClientID %>");
                                var upload = $find("<%= radUploadFiles.ClientID %>");
                                var inputs = upload.getUploadedFiles();
                                var retVal;
                                if (hiddenFile != null && hiddenFile.value != "" && inputs.length == 0) {
                                    retVal = confirm("FYI - Only 'Referral Form' is attached. Do you want to proceed without any other attachment?");
                                }
                                return retVal;
                            }
                        </script>

1 个答案:

答案 0 :(得分:2)

<asp:CustomValidator ID="validatePostBack" runat="server" Display="None" ClientValidationFunction="Validate_PostBack"
                        ValidationGroup="SaveRequestGroup" ErrorMessage="<br /> Please add other attachment."></asp:CustomValidator>                  
                    <telerik:RadScriptBlock ID="uploadReferel" runat="server">
                    <script language="javascript" type="text/javascript">
                        function Validate_PostBack(sender, e) {
                            var hiddenFile = this.document.getElementById("<%= hfInputForm.ClientID %>");
                            var upload = $find("<%= radUploadFiles.ClientID %>");
                            var inputs = upload.getUploadedFiles();

                            if (hiddenFile != null && hiddenFile.value != "" && inputs.length == 0) {
                                var retVal = confirm("FYI - Only 'Referral Form' is attached. Do you want to proceed without any other attachment?");
                                if (retVal == true) {
                                    e.IsValid = true;
                                }
                                else {
                                    e.IsValid = false;
                                }
                            }
                        }
                    </script>
                    </telerik:RadScriptBlock>

找到我的解决方案并且工作正常