Array extensions in ASP.NET AJAX client side framework

This entry is part 7 of 13 in the series ASP.NET Ajax

ASP.NET AJAX client side framework also extend the JavaScript array object and provides ability to work with the array in the similar way as we work in the server side. Create an .aspx page and write the below code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Client Side Event in ASP.NET Ajax</title>
<script language="javascript" type="text/javascript">
function pageLoad() {
var string = '';
var array = ['w3','mentor'];
Array.add(array, '.com');
for (var i = 0; i < array.length; i++) {
string += array[i] + ' ';
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="SM1" />

You will notice that as soon as the page loads, you will get “” alert because of the Array object used in the pageLoad.
Now remove the ScriptManager and try to call the pageLoad() function on body load like below.

<body onload="pageLoad()">

You will get error as there is no Array.Add method in the JavaScript, it is the part of ASP.NET AJAX client side framework that comes out of ScriptManager.
The way Array.Add works, in the same way you can use other methods of Array eg. addRange, clear, contains, enqueue, dequeue, indexOf, insert etc.

Series Navigation«PageLoad event in ASP.NET AJAX using ScriptManagerString extension in ASP.NET AJAX»

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.