Step: 1 Create a web-site ( http://manas6/aspnet.35/mm.SimpleScriptManager1/ )

Add a Microsoft JavaScript File

Step: 2 Add codes in simple.js

function do_something() {
var doc = document.getElementById("Span1");
doc.innerHTML += "<br/><font color='Green'> Hello world</font>";

}
window.onload = function() {
function() { do_something() };
}

 

Step : 2 Simple reference to JavaScript is not adequate, we need to bridge this script to server runtime phase using ScriptManager in Ajax Extension

Default.aspx.

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

<!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>mm.SimpleScriptManager1 : </title>

</head>
<body>
<form id="form1" runat="server">
<div> <asp:Button ID="Button1" runat="server" Text="Page-Load()"
onclick="Button1_Click" /> &nbsp &nbsp
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts> <asp:ScriptReference Path="~/simple.js" /></Scripts> </asp:ScriptManager>
<a onclick="javascript:do_something();"> Click Me: A Script Function</a><br />
<span id="TaskMessage" runat="server">
</span>
<span id="Span1" runat="server">
</span>

</div>
</form>
</body>
</html>
 

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
private static int n1;
protected void Page_Load(object sender, EventArgs e)
{
TaskMessage.InnerHtml ="Page Loaded" + Convert.ToString(n1++) + "Times" ;
}
protected void Button1_Click(object sender, EventArgs e)
{
// just to fire page load
}
}

 

Step: 4 Runtime analysis

Now click on Click Me: , few times, note the text loaded without going through page load.

Now click of Page-Load() button, the page is loaded 1 time, and note that all other scripts are wiped out.