Reputation: 148
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. The user can choose Yes to continue with import or No to cancel import. I have tried the
onClientClick
method of the
asp:Button
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#
. 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
Somehow, I can't seem to get it to work with my solution because they have some updatePanel
they are using. I am using just the DatePicker
, a DropDownList
(for selecting which client to import data for) and a hidden field (if required). Please help if you can. I can be a tweak of any of the above or a completely new solution. Thanks.
Upvotes: 1
Views: 3899
Reputation: 647
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>
Upvotes: 1
Reputation: 330
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 .
Upvotes: 1