Me.ClientScript.RegisterStartupScript (Type, Key, Script, AddScriptTags)
type: The type of the startup script to register.
key: The key of the startup script to register.
script: The startup script literal to register.
addScriptTags: A Boolean value indicating whether to add script tags.
Me.ClientScript.RegisterStartupScript (Me.GetType(), "alert", "alert('Hello world!');", True)
But if you’re using Infragistics controls that offer async postbacks, like WARP panel or UltraWebTab – there is a problem with this approach. Since the page doesn’t go through the full postback and doesn’t get destroyed and re-rendered from scratch – this method doesn’t work.
One approach is to create a literal control (either static in ASPX markup or dynamic thru code) and assign it the code that needs to be executed on the client:
It works, but it can become messy and hard to maintain. A much better approach is to use Infragistic’s CallBackManager’s AddScriptBlock method:
page: Reference to Page.
ownerOfAsyncPostBack: Control, caused async postback. If that parameter is Nothing, then script is added regardless of the owner of postback.
Infragistics.WebUI.Shared.CallBackManager.AddScriptBlock(Me, Nothing, "alert('Hello World!');")
To make it universal we can combine both original ASP.NET approach for full postback and the Infragistics method for async postback into a single function:
Therefore we combine examples from above into a single call: