I want to alert 1 registering the scripts in this order
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert(a);", true);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "b", "var a = 1;", true);
But doing this causes a error saying a is undefined.
I have different controls located in different parts of the page registering scripts, and some of them need to go first and others need to go last.
Is there a way to set order it will render?
No, it’s not possible to define the order in which the
RegisterClientScriptBlockmethods are called. From the documentation for theScriptManager.RegisterClientScriptBlockmethod (emphasis mine):Also, you may want to define a different key (second parameter;"a") for the second invocation ofRegisterStartupScriptBlock, since a registered script is uniquely identified by its key. If you’re calling this method with your parameters,ScriptManagerwon’t register the second script, because another script with the same key ("a") has already been registered.