[英]How to get confirm box return value in ASP.NET C#
I know a number of people have asked similar questions already. 我知道已经有很多人问过类似的问题。 I've read tons of the answers given but none seems to solve my problem.
我已经读了很多给出的答案,但似乎都无法解决我的问题。 I have a form that allows the user to select a file and pick a date that the file should be imported from.
我有一个允许用户选择文件并选择文件导入日期的表格。 When the date is less (before) the last import period (which is a field in database keeping track of last import dates), I want to display a
confirmbox
to alert the user that continuing with the import could overwrite some data. 当日期少于最后导入时间(之前)(数据库中跟踪上次导入日期的字段)时,我想显示一个
confirmbox
以警告用户继续进行导入可能会覆盖一些数据。 The user can choose Yes to continue with import or No to cancel import. 用户可以选择是继续导入,或者选择否取消导入。 I have tried the
我尝试了
onClientClick
的OnClientClick
method of the 的方法
asp:Button
ASP:按钮
control. 控制。 The problem with that was, it gets fired immediately the user clicks the submit button and I don't want to display the confirm box until I have checked with the last import period which will be done on the server-side
C#
. 问题在于,它会在用户单击“提交”按钮后立即被触发,并且直到我检查了最后一个导入期间(在服务器端
C#
上完成)之后,我才希望显示确认框。 I have tried writing the return value to a hidden field like this: 我试图将返回值写入这样的隐藏字段中:
if (confirm("This Import Process Will Overwrite Existing Data. Do You Want to Continue?")) {
document.getElementById("ans").value = "Yes";
return true;
} else {
document.getElementById("ans").value = "No";
return false;
}
That did not work either. 那也不起作用。 I have tried the solution from here: Javascript confirm message problem
我从这里尝试过解决方案: Javascript确认消息问题
Somehow, I can't seem to get it to work with my solution because they have some updatePanel
they are using. 不知何故,我似乎无法使其与我的解决方案一起使用,因为他们正在使用一些
updatePanel
。 I am using just the DatePicker
, a DropDownList
(for selecting which client to import data for) and a hidden field (if required). 我仅使用
DatePicker
, DropDownList
(用于选择要为其导入数据的客户端)和隐藏字段(如果需要)。 Please help if you can. 如果可以的话请帮忙。 I can be a tweak of any of the above or a completely new solution.
我可以对以上任何一种或全新的解决方案进行调整。 Thanks.
谢谢。
Try this , Its work fine for me : 试试这个,对我来说工作正常:
var c = confirm('Your message');
if (c == true)
{
document.getElementById('<%= HiddenField1.ClientID %>').value = 1;
}
else
{
document.getElementById('<%= HiddenField1.ClientID %>').value = 0;
}
You can access the HiddenField in your code behind . 您可以在后面的代码中访问HiddenField。
Try this..You will get the value yes or no to hidden field 尝试此操作。您将获得隐藏字段的值“是”或“否”
<script type="text/javascript">
function ShowConform() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
var cn = document.forms[0].appendChild(confirm_value).value;
//alert(cn);
var c=document.getElementById('<%= hiddenfeid.ClientID %>').value
c = cn;
// alert(c);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.