/ Published in: VB.NET
Gets a ClientScriptManager reference from the Page class. If the client script is not already registered on the page, builds and registers a script. Useful for building a script dynamically and ensuring that it gets registered during the correct stage of the page life cycle.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Private Sub RegisterJavascript() ' Define the name and type of the client scripts on the page. Dim ClientScriptName As String = "LinkClick" Dim PageType As Type = Me.GetType() ' Get a ClientScriptManager reference from the Page class. Dim csm As ClientScriptManager = Page.ClientScript ' Check to see if the client script is already registered. If (Not csm.IsClientScriptBlockRegistered(PageType, ClientScriptName)) Then Dim ClientScriptText As New StringBuilder() ClientScriptText.AppendLine("function ToAccountDetails(un) {") ClientScriptText.AppendLine(" document.getElementById(""UserName"").value = un;") ClientScriptText.AppendLine(" document.getElementById(""frmToAccountDetails"").submit();") ClientScriptText.AppendLine("}") csm.RegisterClientScriptBlock(PageType, ClientScriptName, ClientScriptText.ToString(), True) End If End Sub