Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used below function in inside the button click after the success message come continue our further process if not come success to show the popup with yes/no if click no process is stop click no stop the process.but the below code the script is show after the process is completes how to do it?


What I have tried:

ASPX
 
 <script type = "text/javascript">
function Confirm() {
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";
}
document.forms[0].appendChild(confirm_value);
}
</script>
 
 
 
Code Behind
 
 
protected bool ValidateDuplicate()
{
bool result = true;
Material material = new Material();
MaterialDataAccess materialDA = new MaterialDataAccess();
if (hfdMode.Value.Equals("new") || hfdMode.Value.Equals("draft"))
{
material.Type = "N";
}
else if (hfdMode.Value == "update")
{
material.Type = "U";
}
material.RequestNo = hfRequestNo.Value;
material.Description = tbxShortDescription.Text.ToUpper().Replace("'", "''");
materialDA.Material = material;
materialDA.ValidateCheck();
if (!materialDA.Message.Text.Equals("SUCCESS"))
{
ClientScript.RegisterStartupScript(typeof(Page), "Confirm", "<script type='text/javascript'>callConfirm();</script>");
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
// event occures
}
else
{
// do nothing
}
}
return result;
}
Posted
Updated 24-Jan-18 0:53am
Comments
[no name] 24-Jan-18 6:51am    
What is your issue?What i found from your question is that you are showing a confirm java script message box and registering that call from C#.Once user gets that message box if user selects 'NO' then the form shouldn't post back and if the response is yes then the form should post back but in your case nothing is happening right?Let be clear with my understanding.
Raja Ganapathy 24-Jan-18 6:59am    
yes

1 solution

RegisterStartupScript isn't stopping server-side execution to run script on the client and wait for a response, all it is doing is adding the javascript you specify to the output and continues on. The browser only gets the html (and therefore runs the js) after all of your server code has finished running. There are a few ways to handle getting a confirmation to continue something, it might involve splitting your task into two distinct steps.

Asking the user to confirm that they want to continue with an action | The ASP.NET Forums[^]

The technique you're using can't be "fixed", you're going to have to re-architect your process.
 
Share this answer
 
Comments
Karthik_Mahalingam 24-Jan-18 7:04am    
5
Raja Ganapathy 25-Jan-18 5:35am    
Hi Thank you i have used another method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900