Call javascript method from code behind

Sometime I found it more efficient to run JavaScript on rather than doing everything on VB/c#.

Hope do you call a JavaScript by using the code behind aspx?

You can use the following code

Page.ClientScript.RegisterStartupScript(Me.GetType, “Key name”, “Javascript that you would like to use”, ‘Add script tag)

Here it is an example (“Hello OurChiWai”)
Page.ClientScript.RegisterStartupScript(Me.GetType, “MyJS”, “alert(‘Hello OurChiWai’);”, true)

Page.ClientScript.RegisterStartupScript(this.GetType, “MyJS”, “alert(‘Hello OurChiWai’);”, true);

‘I called my Key “MyJS”
The JavaScript that I am going to run is to do a message box which shows “Hello OurChiWai”

Happy coding.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.