Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page throws JavaScript runtime error: 'Function name' is undefined. IE10 only

While working on IE10, I have found that the JavaScript functions which are registered or called from the code behind are throwing exception:

"JavaScript runtime error: 'function name' is undefined".

For ex: Code behind in the (!IsPostBack) block:

Page.RegisterStartupScript("showGCAlert", "<script language=\"javascript\">ShowGCAlert();</script>");

PageView:

function ShowGCAlert()
    {

        alert('GCAlert');
        if(document.getElementById('hdnGCAlert').value != "1")
        {
            document.getElementById('divGCAlert').style.display = "Block";
            document.getElementById('chkReminder').focus();
            document.getElementById('btnLogin').disabled = true;
            document.getElementById('Button2').disabled = true;             

        }
        else
        {
            document.getElementById('divGCAlert').style.display = "none";
            document.getElementById('btnLogin').disabled = false;
            document.getElementById('Button2').disabled = false;                
            if (document.getElementById("txtUsername").value != "")
                document.getElementById("txtPassword").focus();
            else
                document.getElementById("txtUsername").focus();
        }

    }

When the page loads its throws the exception even though the ShowGCAlert() exists on the dynamic page.

After continuing the exception design page shows:

<script language="javascript" src="/ABC/DEF/Scripts/Common.js"></script>
<script language="javascript">
    document.body.style.overflowY="hidden";
    document.body.style.overflowX="hidden";
    var jsAppName ='ABC';
</script>
<script language="javascript">
    function window.onresize() 
    { 
        document.cookie = "resX=" 
                        + document.body.clientWidth 
                        + ";resY=" 
                        + document.body.clientHeight 
                        + ";path=/"; 
    } 
    window.onresize();
</script>
<script type="javascript">
      ShowGCAlert();
</script>
<script language="javascript">
    document.getElementById('txtPassword').focus();
</script>

In ie9 or IE10 compatibility view its working fine. Please show me where i am doing wrong.

like image 418
Maybe2013 Avatar asked Apr 19 '26 04:04

Maybe2013


1 Answers

Try placing the script at the end of the page using RegisterClientScriptBlock and call it.

   Page.ClientScript.RegisterClientScriptBlock("showGCAlert", 
     "<script type=\"text/javascript\">ShowGCAlert();</script>");
like image 55
Murali Murugesan Avatar answered Apr 20 '26 18:04

Murali Murugesan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!