Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务器端函数调用客户端Javascript函数获取结果_Javascript_Asp.net_Vb.net - Fatal编程技术网

服务器端函数调用客户端Javascript函数获取结果

服务器端函数调用客户端Javascript函数获取结果,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,在asp.net web应用程序中,是否可以在服务器上的类中编写一个调用客户端javascript函数的函数,该函数抛出一个提示框,然后等待用户的响应 我有一个函数,它成功地调用了客户端javascript并显示了提示框,但该函数并不等待用户的响应,代码始终在运行。 有没有办法让它等待响应 代码隐藏功能: Protected Friend Shared Sub ShowDepthQuestion(sLaborId As String) Try

在asp.net web应用程序中,是否可以在服务器上的类中编写一个调用客户端javascript函数的函数,该函数抛出一个提示框,然后等待用户的响应

我有一个函数,它成功地调用了客户端javascript并显示了提示框,但该函数并不等待用户的响应,代码始终在运行。 有没有办法让它等待响应

代码隐藏功能:

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
    <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>
Protected Friend共享子ShowDepthQuestion(sLaborId作为字符串)
尝试
Dim sQuestion As String=mDatabase.GetSingleValueString(“从laboroverride\u hdr中选择问题,其中hdr\u id=“+mDatabase.AddQuotes(sLaborId),无任何内容)
Dim cs As ClientScriptManager=mFrom.ClientScript
如果不是mFrom.ClientScript.IsClientScriptBlockRegistered(“devTeam”),则
cs.RegisterStartupScript(mFrom.GetType(),“devTeam”,“AskDepthQuestion”(+mDatabase.AddQuotes(sQuestion)+”);)
如果结束
'TODO需要代码才能从此处的用户获得响应
特例
WebFunctions.UnhandledPageError(mFrom,例如,“Depth.Retrieve.Functions.ShowDepthQuestion”)
“返回”
结束尝试
端接头
客户端Javascript函数:

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
    <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>

函数AskDepthQuestion(问题,上下文){
var ans=window.prompt(问题“0”);
而(!IsNumeric(ans)){
如果(是数字(ans)){
返回ans;
}else if(ans==null){
返回ans;
}否则{
ans=window.prompt(“答案必须是数字!”+“\n”+问题,上下文);
}
}
}
函数为数字(n){
return!isNaN(parseFloat(n))和&isFinite(n);
}

在此方面的任何帮助都将不胜感激。谢谢

您可能需要使用AJAX。让您的服务器代码调用弹出窗口,并让弹出窗口调用服务器端的另一个方法,以便在用户提交时进行处理。AJAX可以对服务器端进行客户端调用。因此,您最初的方法将弹出弹出窗口,AJAX将调用服务器上的另一个方法来处理提交。

谢谢!我对代码做了一些更改,但似乎无法点击代码中的函数。不是返回ans,而是传入应答CallServer(ans);函数调用服务器(sAns){$.ajax({type:“POST”,url:“frmCrewList.aspx.vb/TimeOutDepth”,数据:{}),contentType:“application/json;charset=utf-8”,数据类型:“json”,成功:函数(msg){if(msg.d=“success”)返回true;否则返回false;};}调用的函数位于代码隐藏中,并声明为uPublic Sub TimeOutDepth()。请确保webmethod声明为静态。我将其声明为共享,但运气不佳。仍然没有找到隐藏的代码。要从url属性中删除.vb,请尝试url:“frmCrewList.aspx/TimeOutDepth”