Step: 2 Add codes
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Debug="true"%>
<!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 id="Head1" runat="server">
<title>mm.JavaScriptArray4: dequeue, enqueue</title>
<style type="text/css">
body { background-color:Gray; color:White }
#div1 { width:400px; height:250px; background-color:#FEFDDE;
color:Navy; padding-left:10px;
}
#display
{
width:300px; height:200px; background-color:#FEEDDE; color:Navy;
padding-left: 10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button4" runat="server" Text="Page-Reload" onclick="Button4_Click"
/>
<asp:Button ID="Button5" runat="server" Text="Clear-Deck"
onclick="Button5_Click" BackColor="#0066FF" Font-Size="Medium"
ForeColor="#FFFF99" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate><asp:Panel ID="Panel1" runat="server"
Width="431px">
Keep these buttons within a panel to enforce click <br />events in
the embedded
script. <br />
<asp:Button ID="Button1" runat="server" Text="Array-foreach" />
<asp:Button ID="Button2" runat="server" Text="Array-dequeue" />
<asp:Button ID="Button3" runat="server" Text="Array-enqueue" />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div id="div1"> This will contain result: Must use Clear Deck button
<br />to clear up the display, and use other
Buttons.<br />
<asp:Label ID="display" runat="server" Text="Label"></asp:Label>
</div>
<br />
</div>
<script type="text/javascript" >
$addHandler($get("Button1"), "click", start);
$addHandler($get("Button2"), "click", do_dequeue);
$addHandler($get("Button3"), "click", do_enqueue);
var _array = new Array();var result = "";
_array = Array("emp1@gmail.com", "emp2@gmail.com", "emp3@gmail.com",
"emp4@gmail.com");
//("emp1@gmail.com', 'emp2@gmail.com', 'emp3@gmail.com', 'emp4@gmail.com");
_array[6] = "manager@gmail.com";
function process(element, index, array) {
// "this" is the context parameter, i.e. '|'.
result += "<br/>" + element + this + index + ',';
}
function start() {
clear();
//alert();
result = "";
Array.forEach(_array, process, '|');
$get("display").innerHTML += result;
}
function do_dequeue() {
// alert("Do_dequeue");
clear();
$get("display").innerHTML += "<br/>Using dequeue";
Array.dequeue(_array);
Array.forEach(_array, process, '|');
//start();
$get("display").innerHTML +=result; ;
}
function do_enqueue() {
$get("display").innerHTML = "";
clear();
Array.enqueue(_array, "new_emp@gmail.com");
Array.forEach(_array, process, '|');
$get("display").innerHTML += "<br/>--- do_enqueue :---<br/>"+
result; ;
}
function clear() {
result = "";
alert("clearing/reloading array ");
$get("display").innerHTML = "";
}
window.onload = function() {
_array; result;
// start();
}
</script>
</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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button4_Click(object sender, EventArgs e)
{
//
}
protected void Button5_Click(object sender, EventArgs e)
{
}
}