Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

calling JavaScript function from VB

I'm trying to call a JavaScript function from VB on button click.

Below is my code.
Why is the alert message not coming up when I click the button?

Call_JSFunctionFromVB1.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Call_JSFunctionFromVB1.aspx.vb" Inherits="TelerikWindow3Level.Call_JSFunctionFromVB1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function HelloFunctionVB1() {
            alert('Hello you called a JS function from VB')
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
         <asp:Button ID="Button1" OnClick="Button1_Click" runat="server" Text="Button" />
    </div>        
    </form>
</body>
</html>

Open in new window


Call_JSFunctionFromVB1.aspx.vb


Public Class Call_JSFunctionFromVB1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        ' ----- call JavaScript function -----
        Dim script As String = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(HelloFunctionVB1);</script>"
        ClientScript.RegisterStartupScript(Me.[GetType](), "showWindow", script)
        ' ----- call JavaScript function -----

    End Sub


End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial