Skip to content

Instantly share code, notes, and snippets.

@ryanmcdonough
Created August 21, 2012 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmcdonough/3415335 to your computer and use it in GitHub Desktop.
Save ryanmcdonough/3415335 to your computer and use it in GitHub Desktop.
Run JQuery from within VB.NET
Public Function runJQueryCode(ByVal message As String) As Boolean
Dim requestSM As ScriptManager = ScriptManager.GetCurrent(Page)
If requestSM IsNot Nothing AndAlso requestSM.IsInAsyncPostBack Then
ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(message), True)
Else
Page.ClientScript.RegisterClientScriptBlock(GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(message), True)
End If
Return True
End Function
Private Function getjQueryCode(ByVal jsCodetoRun As String) As String
Dim sb As New StringBuilder()
sb.AppendLine("$(document).ready(function() {")
sb.AppendLine(jsCodetoRun)
sb.AppendLine(" });")
Return sb.ToString()
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment