Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Register a javascript function
From Wiki
Summary: Register a javascript function
There are a couple of ways to register javascript from your ASP.NET code behind pages. Firstly, if you want to register a function piece of javascript code that will run when the page loads, you can use the ClientScript.RegisterStartupScript method. Here's a simple example:
- ClientScript.RegisterStartupScript(Me.GetType(), "myjavascript", "alert('hello');", True)
Secondly, you may just want to register a function on the page so that other methods can call it. This is where the ClientScript.RegisterClientScriptBlock method comes in:
- Dim myFunction As New StringBuilder
- myFunction.AppendLine("function callMe() {")
- myFunction.AppendLine("alert('hello');")
- myFunction.AppendLine("}")
- ClientScript.RegisterClientScriptBlock(Me.GetType(), "myjavascript", myFunction.ToString, True)
In the above example, you can now call the javascript "callMe" function from other elements on your page.
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.