Injecting a Startup Script Block
Next, we can convert our static script into a dynamically injected startup script. This can be accomplished by adding a single method to the code-behind that injects the static code using the Page.RegisterStartupScript method, passing the script as text to that method. Listing 2 demonstrates the code-behind method.
Listing 2 Registering a Startup Script Block.