How to emit client-side javascript blocks from VB.NET/C#

Platform: ASP.NET|Category: Client Side Scripting

The RegisterStartupScript method emits the script just before the closing tag of the Page object’s <form runat= server> element.

VB.NET

RegisterStartupScript('Sample', '<SCRIPT Language=’javascript’>alert(’Hello World’);</SCRIPT>')

C#

RegisterStartupScript('Sample', '<SCRIPT Language=’javascript’>alert(’Hello World’);</SCRIPT>');

Alternatively, use the RegisterClientScriptBlock method which emits the client-side script just after the opening tag of the Page object’s <form runat= server> element.