Execute JavaScript after a PostBack (VB and C#)


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);
        }

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.