i need to get the user to click OK or CANCEL:
protected void Button1_Click(object sender, EventArgs e)
{
CallRecursive(TreeView1);
string confirmationMessage;
confirmationMessage = @"Please review the data before submitting:" + "\r\n"
+ "Sample Received Date: " + received_dateTextbox.Text + "\r\n"
+ "Site of Ocurrence: " + site_of_occurrenceTextBox.Text + "\r\n"
+ "Occurrence Date: " + occurrence_dateTextBox.Text + "\r\n"
+ "Report Date: " + report_byTextBox.Text + "\r\n"
+ "Specimen ID: " + spec_idTextBox.Text + "\r\n"
+ "Batch ID: " + batch_idTextBox.Text + "\r\n"
+ "Report Initiated By: " + report_byTextBox.Text + "\r\n"
+ "Problem Identified By: " + RadioButtonList1.SelectedValue + "\r\n"
+ nodetexts;
HiddenFieldConfirmation.Value = confirmationMessage;
************i need function ConfirmWithUser() to run here from javascript*************
if (HiddenFieldUserConfirmed.Value != "no")
{
SubmitData();
CallRecursive(TreeView1);
nodetexts += ";";
}
}
here is the javascript:
function ConfirmWithUser() {
if (confirm(document.getElementById('HiddenFieldConfirmation').value) == true)
{ document.getElementById('HiddenFieldUserConfirmed').value='yes'; }
else
{ document.getElementById('HiddenFieldUserConfirmed').value='no';}
how do i run this function ConfirmWithUser() on the button click inside of the code behind code as shown above:
another words i need:
- after user clicks button, first part of codebehind execeutes
- javascript inside of codebehind exeuctes
- the last part of code behind executes
There is no Javascript variable named
confirmationMessage.You need to call
HttpUtility.JavaScriptStringEncodeand insert the server-side variable’s value as a Javascript string literal.However, your design cannot possibly work; the
if (HiddenFieldUserConfirmed.Value != "no")will run (on the server) before the Javascript client-side code.You need to understand how HTTP and client/server separation works.