In an asp.net web application, is it possible to write a function, in a class on the server, that calls a client side javascript function which throws a prompt box then waits for the user's response?
I have a function that successfully calls the client javascript and shows the prompt box but the function doesn't wait for the response from the user, the code behind always keeps going. Is there a way to make it wait for the response?
Code Behind Function:
Protected Friend Shared Sub ShowDepthQuestion(sLaborId As String)
Try
Dim sQuestion As String = mDatabase.GetSingleValueString(" SELECT question FROM laboroverride_hdr WHERE hdr_id = " + mDatabase.AddQuotes(sLaborId), Nothing)
Dim cs As ClientScriptManager = mFrom.ClientScript
If Not mFrom.ClientScript.IsClientScriptBlockRegistered("devTeam") Then
cs.RegisterStartupScript(mFrom.GetType(), "devTeam", "<script language='javascript'>AskDepthQuestion(" + mDatabase.AddQuotes(sQuestion) + "); </script>")
End If
' TODO need code to get the response from the user here
Catch ex As Exception
WebFunctions.UnhandledPageError(mFrom, ex, "Depth.Retrieve.Functions.ShowDepthQuestion")
'Return ""
End Try
End Sub
Client Javascript Function:
<script type="text/javascript">
function AskDepthQuestion(question, context) {
var ans = window.prompt(question, "0");
while (!IsNumeric(ans)) {
if (IsNumeric(ans)) {
return ans;
} else if (ans == null) {
return ans;
} else {
ans = window.prompt("Answer must be numeric!" + "\n" + question, context);
}
}
}
function IsNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
</script>
Any help on this is greatly appreciated. Thanks