Help on adding script to the end of the ASP.NET page after the HTML </body> tag from code behind
Default.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default_Page" %>
-
-
- <!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>Testing</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <p><input type="button" id="myjs" value="Click" /></p>
- </div>
- </form>
- </body>
-
- <!-- Insertted Script should go here after inserted from Code behind -->
-
- </html>
- I would like to add this script or any other script after the </body> tag and before </html> tag from the behind code
- <script>
- document.getElementById("myjs").addEventListener('click', function () {
- alert("Hello World");
- });
Is the above possible?
-
- string MY_SCRIPT_STRING = "<script>alert('Hello Word')</script>";
- this.Controls.Add(new LiteralControl(MY_SCRIPT_STRING));
-
- This works but it adds the code inside the form not at the end of the page where I want the script code to go after the HTML Tag </body> and before </html>
TIA