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.asp x
Call_JSFunctionFromVB1.asp x.vb
Below is my code.
Why is the alert message not coming up when I click the button?
Call_JSFunctionFromVB1.asp
<%@ 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>
Call_JSFunctionFromVB1.asp
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.