Tuesday, October 1, 2013

How to Call a Javascript From Visual Basic


1. Open your Visual Basic application. When the application loads, double-click the web form that has the Javascript you want to run. After it opens, right-click the form and select 'Code View.' This displays the Visual Basic code.
2. Enter the code below in your code-behind file:Page.ClientScript.RegisterStartupScript (Me.GetType(), 'alert', 'alertMe();')The 'Me.etType()' returns Javascript. The 'alert' entry is used to give your Javascript function an internal name for the application. Finally, the 'alertMe()' is the name of your Javascript function.
3. Save the file and press the F5 key. This starts the web application in your web browser. Instead of errors, your Javascript function will run as expected.