Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to fetch the data returned from javascript function to server side in asp.net via c#. Since I need data from Database I am invoking the JS Function to generate a Confirmation Box in server side event under button click. But on clicking OK/Cancel button of the Confirmation Box I am not able to get the data from the hidden field set in the javascript function to server side.

What I have tried:

Javascript Function
JavaScript
//var confirm_value = document.createElement("INPUT");
//   confirm_value.type = "hidden";
//   confirm_value.name = "confirm_value";
var control = '<%=inpHide.ClientID%>';
if (confirm(objMsg)) {
    alert(1);
    document.getElementById(control).value = "1";
    //confirm_value.value = "1";
    return true;
}
else {
    alert(0);
    document.getElementById(control).value = "0";
    //confirm_value.value = "0";
    return false;
}

Code Behind
under button click event
C#
string AlertMessage = "Next Working Day Is On " + NextBusinessDate + " Do You Want To Continue?";
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + AlertMessage + "');", true);
string confirmValue = inpHide.Value;
Posted
Updated 24-Nov-20 22:24pm
v2

1 solution

You need to understand how web applications work. The server-side code runs and generates a response, which is sent to the client. The client then renders the response and executes the client-side code.

Your hidden input value is updated when the client-side code executes. You cannot access the value on the server until the client-side code has executed and the data has been posted back to the server.
 
Share this answer
 

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