2

I have 2 JQuery functions which I want to call from PageLoad event. The current implementation is as under

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), 
"script", "Function1();", true);

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), 
"script", "Function2();", true);

The problem is that, the first function is invoked i.e. Function1 and not Function2.

If I change the order of invocation, then Function2 and not Function1 is called.

How to execute both the functions ?

Thanks in advance.

1 Answer 1

4

You are probably overwritting previous script block with later as you have same key script for both blocks in ScriptManager.RegisterStartupScript call. Give unique name to each script block e.g. name first block as script1 and second as script2 will allow you to call both functions.

SriptManager.RegisterStartupScript(this.Page, this.GetType(), "script1", "Function1();", true);

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script2", "Function2();", true);

In this particular scenario you do not need to register script block twice rather you can have multiple javascript stements in one RegisterStartupScript.

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", 
                                    "Function1();Function2();", true);
Sign up to request clarification or add additional context in comments.

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.