简体   繁体   English

在代码隐藏中调用JavaScript

[英]Calling javascript in codebehind

I am calling javascript via codebehind. 我正在通过代码隐藏调用javascript。 Giving object expected error. 给对象预期的错误。 How can I pass some value through ShowDialog() function? 如何通过ShowDialog()函数传递一些值?

here is my code in codebehind 这是我在代码背后的代码

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog("Value_here");", true);

and in my javascript 在我的javascript中

    <script type="text/javascript">
    var IRProjectID = 0;

    function ShowDialog(UnitID) {
        radconfirm("Are you sure you want to approve this Help Desk item?", confirmBackChecked);
        IRProjectID = UnitID;
    }

    function confirmBackChecked(arg) {
        if (arg == true) {
            __doPostBack(IRProjectID, 'Approve');
        }
    }
    </script>
ClientScript.RegisterStartupScript(this.GetType(), "Call My Function", "ShowDialog("Value_here");", true);

尝试这个

ClientScript.RegisterStartupScript(this.GetType(), "Test", "ShowDialog("+Value_here+");", true);

Perhaps your calling a javascript function too soon... Try with Page.RegisterClientScriptBlock 也许您过早调用javascript函数...尝试使用Page.RegisterClientScriptBlock

Be carefull when you call javascript function. 调用javascript函数时要小心。 Be sure that it exist before!!!. 确保它存在之前!!!

Edit : 编辑

Page.RegisterClientScriptBlock is obsolete, use ClientScriptManager.RegisterClientScriptBlock Page.RegisterClientScriptBlock已过时,请使用ClientScriptManager.RegisterClientScriptBlock

I think the error is thrown by the double quotes you use around Value_here 我认为您在Value_here处使用双引号引发了错误

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog("Value_here");", true);

try this 尝试这个

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog(\"Value_here\");", true);

or 要么

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog('Value_here');", true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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