简体   繁体   中英

Calling javascript in codebehind

I am calling javascript via codebehind. Giving object expected error. How can I pass some value through ShowDialog() function?

here is my code in codebehind

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

and in my 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

Be carefull when you call javascript function. Be sure that it exist before!!!.

Edit :

Page.RegisterClientScriptBlock is obsolete, use ClientScriptManager.RegisterClientScriptBlock

I think the error is thrown by the double quotes you use around 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);

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