0

I am trying to call a Javascript function from my code, but I'm getting the Object Expected js error.

My call to the function:

            ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type=\"text/JavaScript\">returnVal();</script>");

And my javascript from the .aspx

<script language ="javascript">
function returnVal() {
    var hidAppID = document.getElementById("hidAppId");
    var hidAppName = document.getElementById("hidAppName");
    var hidAppSox = document.getElementById("hidAppSox");

    if (window.showModalDialog) {
        var sharedApp = {};
        sharedApp.Id = hidAppID.value;
        sharedApp.Name = hidAppName.value;
        sharedApp.Sox = hidAppSox.value;

        window.returnValue = sharedApp;
    }
    window.close();
}
</script>

The javascript is valid - I added a temporary button to the page to test an "onclicked" call to it. Unfortunately, I need to call it from the code.

4

2 回答 2

1

尝试在没有嵌入标签的情况下调用它,而是传递第三个参数:

ClientScript.RegisterClientScriptBlock(GetType(), "script", "returnVal();", true);
于 2013-07-25T21:27:59.223 回答
0

你已经\returnVal();输入了字符串,这使得\rcarrage返回字符的转义序列,所以你将尝试调用eturnVal不存在的函数。

从代码中删除反斜杠:

ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type=\"text/JavaScript\">returnVal();\n</script>");
于 2013-07-25T21:28:11.557 回答