Javascript 如果按下取消,确认不停止来自 post 的请求?
Javascript Confirm not Stopping request from post back if pressed cancel?
我正在使用带有 confirm()
消息框的 Javascript 函数,并且还有 RequiredFieldValidator
如果我在我的确认消息框上按取消但 ValidatorGroup 为真那么它不会停止来自的请求post 回来了。
我想以这样的方式实现如果 validatorGroup 是 treu 但函数 return false 那么请求不应该 post 返回
这是我的代码:-
<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>
<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>
找到我的解决方案并且工作正常
我正在使用带有 confirm()
消息框的 Javascript 函数,并且还有 RequiredFieldValidator
如果我在我的确认消息框上按取消但 ValidatorGroup 为真那么它不会停止来自的请求post 回来了。
我想以这样的方式实现如果 validatorGroup 是 treu 但函数 return false 那么请求不应该 post 返回
这是我的代码:-
<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>
<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>
找到我的解决方案并且工作正常