⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.aspx

📁 this is the file to chat in web
💻 ASPX
字号:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="main" %>

<!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>AJAX Chat Main Control Page</title>
 		<LINK href="css/global.css" type="text/css">
		<script language="jscript" src="javascript/CLASS_MSN_MESSAGE.js"></script>
		<script src="javascript/common.js" type="text/javascript"></script>
		<style type="text/css">
		A { COLOR: #013da4; TEXT-DECORATION: none }
		A:visited { COLOR: #013da4; TEXT-DECORATION: none }
		A:link { COLOR: #013da4; TEXT-DECORATION: none }
		</style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="Table1" height="100%" cellSpacing="1" cellPadding="1" width="100%" align="center"
				border="2" bordercolor="#0033ff" style="height: 10px; width: 20px;" >
            <tr>
                <td style="width: 3px; height: 38px" align="left">
                    <asp:Label ID="lblUsername" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#2767C8" Width="172px" Height="21px"></asp:Label></td>
                <td style="height: 38px;" align="center">
                    &nbsp;<select id="user_status" name="user_status" style="width: 100px" onchange="setUserStatus()">
                        <option selected="selected" value="1">Online</option>
                        <option value="2">Offline</option>
                        <option></option>
                    </select></td>
                <td style="height: 38px;" align="center">
                    <asp:LinkButton ID="lblExit" runat="server" BorderStyle="Solid" OnClick="lblExit_Click">Logout</asp:LinkButton></td>
            </tr>
            <tr>
                <td bgcolor="#66ff99" colspan="3" style="height: 48px;">
                    <strong style="height: 20px">Online friends list:</strong></td>
            </tr>
            <tr>
                <td colspan="3" bgcolor="#ffffcc" style="height: 369px">
                    <div id="userlist" style="width: 743px; height: 380px">
                    </div>
                </td>
            </tr>
        </table>
    
    </div>
    </form>
		<script language="javascript">
		//used to mark whether the chat room is open
		var sendWindow = false;
		
		//check out whether the user status has been changed
		var changedTimes = 0;
		
		//the main procedure
		mainLoop();
		
		function mainLoop()
		{
			//check the user login status
			checkStatus();
			
			//update the users list
			refreshUserlist();
			
			// check the newest messages
			checkNewMessage();
			
			//invoke function mainLoop every per second
			setTimeout("mainLoop()", 5000);			
		}
		
		//set the selected value
		function setSelectedValue(selectname, value)
		{
			// look up the value which matches the sequence number inside 'select'
			var index = -1;
			var select = el(selectname);
			for (var i = 0;i < select.options.length;i++)
			{
				if (select.options[i].value == value)
				{
					index = i;
					break;					
				}			
			}
			
			// change the order number of the selected item
			select.selectedIndex = index;
		}
		
		//check the user's login status
		function checkStatus()
		{
			//get the user's login status
			
			var status = AjaxProChat.CheckStatus().value;
			
			// set the selected value
			setSelectedValue("user_status", status);
		}
		
		//update the users list
		function refreshUserlist()
		{
		    // get the value of field UsersChanged from inside  table users on the server side
			var changed = AjaxProChat.StatusChanged().value;
			
			// if table users has changed
			if (changed > changedTimes)
			{
				// write down the current value of field UsersChanged
				changedTimes = changed;
				
				// obtain the DataTable object to hold the users info
				var arUserlist = AjaxProChat.GetOnlineUserList().value.Tables[0];
				
				// the <div> object to show the users list
				var divUserlist = el("userlist");
				
				// remove the old contents
				while (divUserlist.childNodes.length > 0)
				{
					divUserlist.removeChild(divUserlist.childNodes[0]);
				}				
				
				//show the users list
				for (var i = 0;i < arUserlist.Rows.length;i++)
				{
					//the login user name
					var username = arUserlist.Rows[i].username;
					
					// nickname
					var nickname = arUserlist.Rows[i].nickname;
					
					// create a <div> object for showing one user message
					var result = document.createElement("div");
					
					//set the cursor shape hand-like
					result.style.cursor = "pointer";
					
					// inner patches
					result.style.padding = "2px 0px 2px 0px";
					
					//mouse click handler--open the chat room window
					result.onclick = function ()
					{
						//if the chat room window has not been opened
						if (!sendWindow)
						{
							// open the chat room window--note the passed parameters
							window.showModelessDialog("chatroom.aspx?username=" + username,
								window,"help:no;unadorned:yes;edge:sunken;resizable:yes;status:no");
						}
					};

					//the texts for the user name and the nickname are to be shown inside the <span> object
					var result1 = document.createElement("span");
					
					//set the mouse in-and-out effect
					result1.onmouseover = function ()
					{
						this.style.color = "#205288";
					};
					result1.onmouseout = function ()
					{
						this.style.color = "#000000";
					};
					
					// set show style
					result1.style.textAlign = "left";
					result1.style.fontWeight = "bold";
					result1.style.fontFamily = "Arial, Verdana";
					
					// show the user name plus the nickname
					result1.innerHTML = username + " (" + nickname + ")";

					// attach the <div> object to DOM
					result.appendChild(result1);
					divUserlist.appendChild(result);
				}			
			}
		}		
		
		//Check new messages
		function checkNewMessage()
		{
			// if the chat room window has not been opened
			if (!sendWindow)
			{
				//get the messages
				var dt = AjaxProChat.mainGetNewMessage().value.Tables[0];
				
				//if there are new messages
				if (dt.Rows.length > 0)
				{
					//the sender
					var sender = dt.Rows[0].sender;
					
					//content
					var content = DealBrackets(dt.Rows[0].content);
					
					// hint content
					var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"Hint:",sender + " says: ",content);
					
					// set up the function in response to the hint message click
					MSG1.oncommand = function()
					{
						if (!sendWindow)
						{
							window.showModelessDialog("chatroom.aspx?username=" + sender, window,"help:no;unadorned:yes;edge:sunken;status:no");
						}
					
					};
					
					//show the pop up hint window
					MSG1.rect(null,null,null,screen.height-50); 
					MSG1.speed = 10; 
					MSG1.step = 5; 
					MSG1.show();  
				}			
			}
		}
		
		//set the user login status
		function setUserStatus()
		{
			//user name
			var username = el("lblUsername").innerText;
			
			//status
			var status = el("user_status").value;
			
			// call the server-side Ajax method
			AjaxProChat.SetUserStatus(username, status);
		}
		
		</script>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -