Execute JavaScript after a PostBack (VB and C#)

Posted by Blake on 4/3/2012
)

Here is an example of how to execute JavaScript after a PostBack in a WebForms page (this specific case is not using ASP.NET Ajax, but rather a synchronous PostBack). This will allow you to run custom JavaScript after the server side code has executed.

VB.Net

    Page.Validate

    If Page.IsValid = True Then
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "script", js, True)
    End If

C#

    Page.Validate();

    if (Page.IsValid)
    {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", js, true);
    }