Ajax开发实例教程.NET页面屏聊系统
http://tech.ddvip.com 2008年05月08日 社区交流
内容摘要:发现使用Asp.Net Ajax开发包去开发要比原来的asp+ajax简单得多,而且开发完后对浏览器的兼容也大大的提高了。因此懒羊这里就再次献丑,将一些开发心得提供出来与大家一起分享,并提供用户控件供大家下载使用。
五、Visual Studio 2005开发步骤
通过以上的学习,我们可以简单的了解屏聊系统的整个开发思路及在开发中所出现的重点难点。读者可以试着去按照功能思路去实际操作一下,下面懒羊把使用VS2005操作的具体步骤附上,但我还是希望读者能够先看一下前面的内容再来看下面的内容:
1、打开VS2005—> 新建—> 网站—> ASP.Net网站;
2、为了方便以后移植,我们为项目添加用户控件。右击项目文件—> 添加新项;
3、拖动ScriptManage控件到页面,并为Scripts属性添加anchormain.js,如下图:

图四 为Scripts属性添加anchormain.js
Anchormain.js为屏聊系统界面客户端代码,其中包括页面位置显示、页面加载、关闭时所触发的事件功能,代码如下,详细可以参照《Ajax开发页面聊天系统》一文。
// JScript 文件
window.onload = getMsg;
window.onresize = resizeDiv;
window.onscroll= resizeDiv;
window.onunload=unloadpage;
window.onerror = function(){alert("程序出错问题,请与懒羊联系!");
var divWidth,divHeight,docHeight,docWidth;
var Timer2Flag=1;
function resizeDiv()
{
try{
divHeight = parseInt(document.getElementById("eMsg").offsetHeight,10);
divWidth = parseInt(document.getElementById("eMsg").offsetWidth,10);
document.getElementById("eMsg").style.top =(document.documentElement.clientHeight - divHeight + parseInt(document.documentElement.scrollTop,10))+"px";
document.getElementById("eMsg").style.left = (parseInt(document.documentElement.scrollLeft,10) + document.documentElement.clientWidth - divWidth)+"px";
}
catch(e){
}
}
function moveDiv()
{
try
{
if(parseInt(document.getElementById("eMsg").style.top,10) <= (docHeight - divHeight + parseInt(document.documentElement.scrollTop,10)));
{
window.clearInterval(objTimer);
objTimer = window.setInterval("resizeDiv()",1);
}
divTop = (parseInt(document.getElementById("eMsg").style.top,10))+"px";
document.getElementById("eMsg").style.top =( divTop - 1 )+"px";
}
catch(e){
}
}
function getMsg()
{
try{
document.getElementById("AnchorCall1_Max").style.display="none";
divHeight = parseInt(document.getElementById("eMsg").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMsg").offsetWidth,10)
docWidth = document.documentElement.clientWidth;
docHeight = document.documentElement.clientHeight;
document.getElementById("eMsg").style.top =(parseInt(document.documentElement.scrollTop,10) + docHeight + 10)+"px";// divHeight
document.getElementById("eMsg").style.left =(parseInt(document.documentElement.scrollLeft,10) + docWidth - divWidth)+"px"; document.getElementById("eMsg").style.visibility="visible" ;
objTimer = window.setInterval("moveDiv()",10) ;
}
catch(e){}
}
function changemax() //还原屏聊系统
{
document.getElementById("AnchorCall1_Min").style.display="none";
document.getElementById("AnchorCall1_Max").style.display="";
}
function changemin() //最小化屏聊系统
{
document.getElementById("AnchorCall1_Min").style.display="";
document.getElementById("AnchorCall1_Max").style.display="none";
}
function closeMsg()//关闭屏聊系统
{
document.getElementById("eMsg").style.display="none";
}
function unloadpage()
{
__doPostBack("AnchorCall1$close","")
}
function stopTimer2()
{
if(Timer2Flag==1)
{
__doPostBack("AnchorCall1$Button2","");
Timer2Flag=0;
}
}
function startTimer2()
{
__doPostBack("AnchorCall1$Button1","");
Timer2Flag=1;
}
function keypress(event)
{
var keycode = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
if((keycode==83)&&(event.altKey)){
__doPostBack("AnchorCall1$ImageButton1","");
}
}
来源:it168 作者:懒羊 责编:豆豆技术应用