gpt4 book ai didi

如果按下取消,Javascript 确认不会停止回发请求?

转载 作者:行者123 更新时间:2023-11-29 21:04:09 25 4
gpt4 key购买 nike

我将 Javascript 函数与 confirm() 消息框一起使用,并且还具有 RequiredFieldValidator 如果我在确认消息框上按取消但 ValidatorGroup 为 true 那么它不会停止请求回发。

我想以这样的方式实现如果 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>

最佳答案

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

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

关于如果按下取消,Javascript 确认不会停止回发请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44897762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com