我如何使用后端(C#)触发函数(javascript)

时间:2019-07-10 06:45:37

标签: javascript c# asp.net

我在调用函数(showpincode())时遇到问题,但该值不起作用,您可以帮我吗。我使用后端调用它,但值(txtRequestEncrypted.text)不起作用

BACKEND C#

 List<Upload> c = new List<Upload>();
                c.Add(b);
                a.UploadCardDetails = c;

                a.ProgramName = null;
                a.IPAddress = "111.222.33.444";
                a.Authentication = "Basic RXFNzdzw==";
                object obj = a;
                string test = JsonConvert.SerializeObject(obj);


                string pkey = "test";
                string psalt = "test1";
                string Result = Utilities.Utilities.test1(test, pkey, psalt);

                txtRequestEncrypted.Text = Result.ToString();

this.Controls.Add(new LiteralControl("<script type='text/javascript'>ShowPINPad();</script>"));

JAVASCRIPT验证以访问密码

<script type="text/javascript">

        window.addEventListener("message", function (ev) {
           "https://testtest.com.ph/index"
            //event origin of virtual pin pad
            $origin = ev.origin;
            //event source of virtual pin pad
            $source = ev.source;
            //IMPORTANT: CHECK THE ORIGIN OF THE DATA!
            if (ev.origin.indexOf($sourceURL)) {
                if (ev.data.message === "deliverResult") {
                    ev.source.close();
                }
                else if (ev.data.message == "RESEND") {
                    txtResponse
                    try {

                        setTimeout(function () {
   var requestData = $('#<%= txtRequestEncrypted.ClientID %>').val();

                            child.postMessage({ message: "requestResult", encryptedRequestData: requestData}, "*");
                        }, 3000);
                    } catch (e) {
                        //checking the virtual pin pad is closed
                        if (child.closed) {
                            console.log('Error encountered when calling virtual pinpad...');
                            clearTimeout(interval);
                            //do something
                            document.getElementById("txtResponse").value = "CLOSED";
                            document.getElementById("txtResponseEncrypted").value = "";
                            return;
                        }
                    }
                }
        }
        });

这是显示Pinpad的功能

 var child = null;

    function ShowPINPad() {
        var height = 406;
        var width = 450;
        var left = Math.round((screen.width / 2) - (width / 2));
        var top = Math.round((screen.height / 2) - (height / 2));
        var targetURL = "https:test.com.ph/index"
        child = window.open(targetURL, "_blank", "scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no,copyhistory=no,height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ";");
        // child.focus();
    }

2 个答案:

答案 0 :(得分:0)

Page.ClientScript.RegisterStartupScript(this.GetType(),“ CallMyFunction”,“ MyFunction()”,true);

在此链接上查看更多详细信息

Calling JavaScript Function From CodeBehind

答案 1 :(得分:0)

请按照以下代码从后面的代码中调用javascript函数:

string jquery = "drawImage();"
 ClientScript.RegisterStartupScript(typeof(Page), "a key", 
 "<script type=\"text/javascript\">"+ jquery +"</script>"
           );

有关更多详细信息: Call javascript function from code behind