How to call JavaScript function on page load in asp.net c#

In this article, we have seen that how to call JavaScript function on page load on asp.net. In this post, we pop up the alert box of java script on 5 sec.


Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="p2.aspx.cs" Inherits="p2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
        function timeoutpop() {
setTimeout(function () { alert("Welcome in Code Solutions"); }, 5000);

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
          
    </form>
</body>
</html>

Code behind(c#):-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class p2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, typeof(Page), "Testing", "timeoutpop();", true);
    }
}

Out-Put:-


How to call JavaScript function on page load in asp.net c# How to call JavaScript function on page load in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 10:00:00 PM Rating: 5

No comments:

Powered by Blogger.