简体   繁体   中英

How to call Multiple Java Script function into code behind C#

How to call Multiple Java Script function into code behind C#. I want to call below two function into code behind c#.

    <script type="text/javascript">
    // dateFuture = new Date(2010, 11, 25, 12, 0, 0);

    function f1()
    {
        $find("mpe").show();
        return false;

    }

    function takepic() {
        // first part   
        context.drawImage(video, 0, 0, 320, 240);
        //above line take the picture
        //second part save the picture
        var image = document.getElementById("canvas").toDataURL("image/png");
        alert(image);

        //get raw image data
        image = image.replace('data:image/png;base64,', '');

        $.ajax({
            type: "POST",
            url: "assessment.aspx/SaveUser",
            data: '{"imageData": "' + image + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                alert("User has been added successfully.");
                window.location.reload();
            }
        });
        return false;

    }
 </script>

I have requirement to take a photo from web camera, in first time in f1() function I am showing ajax modal popup for taking photo and user will submit. And second time taking photo directly to calling another function takepic().

I tried but not getting.

    if (QSno == "1")
     {
   Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","f1()",true)
     }
    else if (QSno == "2")
   {
   Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","takepic()",true)
   }

Actually you are registering the same type/key combination more than once, You have to use different for every registration.

So use different keys

if (QSno == "1")
     {
   Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","f1()",true)
     }
    else if (QSno == "2")
   {
   Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction2","takepic()",true)
   }

The script key here is CallMyFunction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM