How to call a JavaScript function on ASP.NET page load Using VB.NET

This blog defines how to call a JavaScript function on ASP.NET.

ASPX code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication11.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">


    <script language="javascript" type="text/javascript">

        function hideButton() {


            document.getElementById("divAbc").style.visibility = "hidden";

            return false;




<div id="divAbc">

<table><tr><td style="width: 200px; height: 100px; background-color: red"></td></tr></table>




<form id="form1" runat="server">  

<asp:Button ID="btnHide" Runat="server" Text="Hide"  />&nbsp;





Now double click on the form and the following code page load event.

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

        btnHide.Attributes.Add("onclick", "return hideButton()")

    End Sub



Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now