1

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>

4 Answers 4

1
ClientScript.RegisterStartupScript(this.GetType(), "Call My Function", "ShowDialog("Value_here");", true);
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

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

1 Comment

can u tell me where r u getting the error exactly.Is it a run time error or compile error.
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

3 Comments

Page.RegisterClientScriptBlock is obsolete.
ClientScriptManager.RegisterClientScriptBlock
¿Do you have a ScriptManager on your page?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.