How To Add multiple dynamic onload events to body tag-ASP.NET

In this article, I will show you how to add multiple onLoad event in the document body on the ASP.NET web page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultipleEvent.aspx.cs"
Inherits="MultipleEvent" %>

<!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>Untitled Page</title>
</head>
<body runat="server" id="body">
   <form id="form1" runat="server">
       <div>
           How To Add multiple dynamic onload events to body tag
       </div>
   </form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MultipleEvent : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        body.Attributes["onload"] = "javascript:alert('Onload Event1');";
        if (body.Attributes["onload"] != null)
        {
            body.Attributes["onload"] += "javascript:alert('Onload Event2');";
        }
        else
        {
            body.Attributes.Add("onload", "javascript:alert('bye')");
        }

    }
}

Please do not post any spam link in the comment box😊

إرسال تعليق (0)
أحدث أقدم