1

I have a problem I call the function (showpincode()) but the value is not working can you help me. I call it using backend but the value (txtRequestEncrypted.text) did not work

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 VALIDATION TO ACCESS THE PINCODE

<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;
                        }
                    }
                }
        }
        });

THIS IS THE FUNCTION to Show 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();
    }
Boleros
  • 11
  • 4
  • 1
    The backend and the client code work in completely different environments and most of the time completely different machines. You can't just expect the backend to execute JS code after it has served the page. You have to make the two communicate in some fashion first. – VLAZ Jul 10 '19 at 06:49
  • @VLAZ, I think bossjerk is simply asking how can he call javascript function from asp.net code. So there is a way to call it. Although, there are other posts already giving answers to it – Khurram Ishaque Jul 10 '19 at 06:55
  • Hi sir Vlaz But i already get the value to access the website but the problem i got is the showpincode site did not pop up! – Boleros Jul 10 '19 at 06:57
  • Hi Khurram ishaque sir i can i call the function (showpincode) using backend. c# – Boleros Jul 10 '19 at 06:59

2 Answers2

0

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

check more Details On This Link

Calling JavaScript Function From CodeBehind

  • Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ShowPINPad()", true); idont get it the "CallmyFunction" – Boleros Jul 10 '19 at 07:20
0

Please follow below code to call javascript function from code behind:

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

For more details: Call javascript function from code behind

Khurram Ishaque
  • 778
  • 1
  • 9
  • 26