I am using Client script for confirm message box as follows
string script = "fadeScript";
ScriptManager.RegisterClientScriptBlock(this.Page, script.GetType(), "Script", "Closewindow();", true);
java script function:
<script type="text/javascript">
function Closewindow() {
var Result = confirm("Are you sure want to delete?");
alert(Result);
if (Result == true) {
document.getElementById('txtConfirmresult').value = Result;//assigning to hidden text box
alert(txtConfirmresult.value);
return true;
}
else
{
document.getElementById('txtConfirmresult').value = Result;//assigning to hidden text box
alert('BYE');
return false;
}
}
</script>
I want to use the script return value in .cs file to excite procedure if it returns true. if it return false i have to stay on that particular page only. plz kindly help me on this
You can use
__doPostBack(target, argument)to post back to the server. You can then evaluate__EVENTTARGETand__EVENTARGUMENTin the post data to see what you sent back and perform logic appropriately. Here is a link that provides a little more in depth information.A quick example:
Script/Client side:
C#
Updated to add slightly more correct variable names, but should work with your existing codebase assuming your script was working. I would be very careful using
txtConfirmresultas your ID as that will only work ifrunat="server"is not set on the textbox. If that is the case, the ID will be prepended to denote container hierarchy.I would suggest naming your “callbacks” very well, such as:
Script/Client side:
C#