kirk
kirk

Reputation: 1007

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>

Upvotes: 1

Views: 609

Answers (4)

user2197722
user2197722

Reputation: 26

ClientScript.RegisterStartupScript(this.GetType(), "Call My Function", "ShowDialog("Value_here");", true);

Upvotes: 1

wsplinter
wsplinter

Reputation: 1061

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);

Upvotes: 0

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

Upvotes: 0

iJade
iJade

Reputation: 23791

Try this

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

Upvotes: 0

Related Questions