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"
<html xmlns="">
<head runat="server">
   <title>Untitled Page</title>
<body runat="server" id="body">
   <form id="form1" runat="server">
           How To Add multiple dynamic onload events to body tag
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');";
            body.Attributes.Add("onload", "javascript:alert('bye')");

Next Post Previous Post
No Comment
Add Comment
comment url