CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

高分求asp.net聊天室源码

楼主toshi315(人)2005-01-26 20:19:38 在 .NET技术 / ASP.NET 提问

各位高手,  
      小弟急着交点东西,需要聊天室源码,必须是asp.net做的,最好无刷屏   啊。  
  如果有详细制作步骤,更好啊!  
                            希望哪位能伸出援助之手!  
                          定将高分相送!  
                      我的邮箱:tongxi315@163.com  
  非常感谢! 问题点数:80、回复次数:7Top

1 楼minghui000(沉迷网络游戏)回复于 2005-01-26 21:06:18 得分 50

Creating   the   webservice:  
  As   mentioned   earlier,   in   a   Peer   to   Peer   application,   the   server   support   is   needed   for   three   actions   -   registering   the   peers,   receiving   messages   for   routing   and   passing   on   waiting   messages.   Therefore,   our   web   service   will   have   three   Web   Methods:  
   
  public   string   RegisterMember(String   NickName)    
  public   ChatMessage   XchangeMsgs(String   NickName,   String   Msg)    
  public   ChatMessage   GetMsgs(String   NickName)    
  The   web   service   is   encapsulated   in   a   class   called   ChatWebService,   which   is   derived   from   System.Web.Servicesand   is   contained   in   the   source   code   fileChatWebService.cs   in   the   namespace   PrasadWeb.   The   namespace   also   defines   two   other   classes   calledMember   and   ChatMessage.   The   classMessage   has   a   string   variable   called   UserName,   a   DateTime   variable   calledLastAccessTime   and   a   public   property   NickName,   which   gets   and   sets   the   variableUserName   together   with   the   time   of   his   registration.   The   ClassChatMessage   has   merely   two   string   variables   calledUserList   and   Messages.   These   two   variables   hold   formatted   lists   of   Chat   Participants   and   the   undelivered   chat   messages   at   any   given   time.  
   
  The   main   classChatWebService   has   two   private   methodsString   GetMemberList()   and   Void   CheckMemberList(),   besides   the   three   Web   Methods   mentioned   earlier.   The   former   function   returns   the   list   of   chat   participants   at   any   given   time   as   a   formatted   list.   The   later   function   checks   to   see   if   any   chat   client   has   been   absent   from   the   circuit   for   more   than   2   minutes   and   removes   him   from   the   chat   list,   so   as   to   keep   the   environment   free   from   quitters.   TheGetMemberList   function   works   as   follows:  
   
  public   String   GetMembersList()  
     {  
  //   We   need   to   lock   the   app   to   enable   syncronization  
    
  //   The   variable   for   the   return   message  
  String   UserList   =   "";  
   
  //   Every   web   application   has   an   Application   property  
  //   which   yields   a   handle   to   the   ApplicationState   object.  
  //   ApplicationState   object   stores   the   collection   of    
  //   Member   Objects   (we   will   see   latter   how   we   do   it).  
  //   We   obtain   an   array   of   the   Keys   to   the   collection  
  //   and   store   the   array   in   a   variable   'Members'  
  String[]   Members   =   Application.AllKeys;  
   
  //   We   can   now   unlock   the   application  
    
  Application.UnLock();  
    
  //   Now   we   read   the   UserName   variable   in   each   Member  
  //   object   found   in   the   HttpApplicationState   State   Collection  
  //   and   store   these   values   in   a   string   separated   by  
  //   NewLine   Characters  
   
  for   (int   x=0;x  
   
  As   the   application   involves   multiple   users   -   all   accessing   the   same   set   of   variables   stored   by   us   in   the   application   object   -   we   need   to   use   Code   Synchronization   by   invoking   theLock   andUnLock   methods   of   theSystem.Web.HttpApplicationState   State   object   whenever   a   write   operation   is   performed   by   us.  
   
  In   theRegisterMember   method,   we   first   check   if   the   username   supplied   by   the   client   is   unique   -   if   not,   reject   the   name.   Then,   we   instantiate   a   newMember   object   for   the   new   participant   and   add   the   object   to   theApplicationState   objects   collection.   We   do   these   with   the   following   code:  
   
   
  public   string   RegisterMember(String   NickName)  
  {  
     CheckMembersList();  
   String[]   Members   =   Application.AllKeys;  
     If   ((Members.Length>0)&&(Array.IndexOf(Members,NickName)>-1))  
     {  
  throw   new   Exception("UserName   Already   Exists.    
  Please   Select   another   name");  
     }  
     Member   NewMember   =   new   Member(NickName);  
     Application.Lock();  
     Application.Add(NickName,   NewMember);  
     Application.UnLock();  
     return   GetMembersList();  
  }  
   
   
  Again,   all   these   are   done   in   alocked   state.  
   
  Whenever   a   client   sends   a   message   through   theXchangeMsgs   method,   we   first   call   theCheckMembers   private   method   to   update   the   list   of   chat   participants   in   our   collection.   Then   we   check   if   the   just   received   message   carries   a   familiar   Nick   Name   that   is   already   registered   with   us.   Then   we   loop   through   all   theMember   objects   in   our   collection,   open   each   of   them   and   insert   the   just   received   message   into   theMessages   variable   of   each   of   theseMember   objects   -   after   due   HTML   Formatting.   Finally,   we   retrieve   theMessages   string   stored   in   theMember   object   corresponding   to   the   current   client   caller   as   the   return   value   and   empty   theMessages   variable   of   that   object.  
   
  TheGetMsgs   web   method   is   similar   to   the   above   except   that   this   method   does   not   being   us   any   new   messages   from   the   client   and   it   is   merely   called   to   collect   all   the   pending   messages   and   the   current   list   of   chat   participants.  
   
   
  Top

2 楼minghui000(沉迷网络游戏)回复于 2005-01-26 21:06:36 得分 0

Creating   the   Chat   Client:  
  Our   Chat   Client   is   an   HTML   Web   Page,   which   contains   a   table   with   7   rows   and   one   column.   The   first   row   contains   the   name   of   the   Chat   Application.   The   even   numbered   rows   bear   the   captions   and   row   number   three   contains   the   Chat   Participants   List   whilst   row   five   is   for   chat   messages.   The   last   row   has   a   Text   Box   and   a   Submit   button.   Rows   three   and   five   house   aelement   within   them,   whosescroll   property   has   been   set   toauto.    
   
  Attaching   the   WebService   Behavior:  
  The   table   webservice   behavior   defined   in   the   webservice_ver1.htc   file,   as   follows:  
   
   
     id="service"    
     onresult="service_onmyresult();"    
     onready="this.style.visibility   =   'visible';loading.style.display='none';"    
     border="0"    
     style=  
     "Background-Color:  
     White;Height:60%;  
     Border-Bottom:#A03399   solid   2px;  
     ForeColor:Black;  
     width:45%;  
     Behavior:url('http://localhost/dotnet/chatroom/webservice_ver1.htc');  
     Border-Left:#99ccff   solid   2px;  
     Border-Right:#A03399   solid   2px;  
     Position:Relative;  
     Visibility:hidden;  
     Width:30%;  
     Border-Top:#99ccff   solid   2px;  
     Table-Layout:Fixed;  
     Border-Style:#008080   solid   2px;">  
   
   
   
  The   page   has   two   script   blocks   of   which   one   is   invoked   on   theonLoad     event   of   the   window.   This   script   block   calls   the   use   method   of   the   webservice   behavior   by   passing   the   URI   of   the   webservice   as   a   parameter   as   follows:    
   
   
   
   
   
  The   other   parameter   supplied   to   the   method   is   the   name   of   the   service   ChatServe.   The   second   code   block   initializes   three   variables   called   iCallID1,iCallID2   and   iCallID3,   to   store   the   ID   of   the   three   web   method   calls.   It   also   initializes   anXMLDom   ActiveX   Object   called   Msg_XML,   to   enable   us   to   store   the   SOAP   messages   returned   by   the   web   service.    
   
  When   the   user   types   his   nick   name   in   the   Text   Box   and   presses   the   submit   button,   an   asynchronous   call   is   made   to   the   Web   Service'sRegisterMember   method,   by   invoking   thecall   method   found   in   the   webservice.htc.   The   method   formats   the   SOAP   request   for   theWeb   Method,   sends   it   to   the   web   service   host   server   using   theXMLHttp   object   of   theMSXML   ActiveX   object   and   returns   the   initializer   for   theiCallID1   variable.   The   DHTML   Behavior   ensures   that   when   the   webservice   returns   a   SOAP   Message   from   the   server,   anonResult   event   is   fired   upon   the   Table.   The   event   handler   for   this   event   first   checks   up   if   the   return   value   is   an   error   message   and   if   not,   whether   the   return   message   is   for   the   iCallID1.   On   passing   these   tests,   the   XML   value   of   the   result   is   stored   in   theXMLDom   object   called   Msg_XML.  
   
  At   this   stage   the   XML   returned   by   the   server   will   resemble   the   following:  
   
   
     
     
  Prasad  
  Uriah  
  Charlotte  
   
   
   
  The   Chat   List   in   the   return   message,   which   isPrasad   Uriah   Charlotte   is   parsed   out   by   applying   the   XPath   pattern//UserList   on   the   XML   String   and   written   into   the   table   as   the   inner   HTML   of   the   Chat   List   panel   as   follows:  
   
   
  service_ChatList.innerText   =   service_MsgXML.selectSingleNode("//UserList").text;  
   
   
  The   method   then   goes   on   to   set   a   timer   to   invoke   theGetMsgs   method   of   the   web   service   after   3   seconds.   The   return   value   of   this   method   is   parsed   and   placed   as   the   inner   HTML   of   the   Chat   List   panel   and   the   Chat   Messages   panel   of   the   Table.   This   method   sets   up   a   timer   to   call   itself   once   every   3   seconds.    
   
  Whenever   the   client   types   a   message   in   the   text   box   and   presses   the   submit   button,   theXchangeMsgs   method   of   the   web   service   is   invoked   by   the   DHTML   Behavior   component.   The   return   value   of   this   method   being   similar   to   the   one   described   above,   is   dealt   with   in   the   same   manner.  
   
  This,   in   brief,   is   the   designing   of   the   client   object.   You   will   need   to   take   a   deeper   look   into   theClientSide.html   file   given   in   the   code   download   for   this   article   to   read   the   intricate   details   of   the   client   side   coding   involved.  
   
  Top

3 楼minghui000(沉迷网络游戏)回复于 2005-01-26 21:07:10 得分 0

Making   a   control   for   the   client   side:  
  All   that   was   described   in   the   preceding   section   was   the   HTML   code   required   to   be   supplied   to   the   client   browser.   However,   since   ASP.NET   is   based   on   components,   we   need   to   make   it   easy   for   the   web   developer   by   encapsulating   all   these   HTML   code   into   a   Control.   Therefore,   let   us   go   on   to   create   the   ASP.NET   custom   control   called   TestWebControl.   (See   the   code   listing   in   the   file   TestWebControl.cs).    
   
  This   control   is   derived   from   theSystem.Web.UI.WebControls.table   object   of   the   Framework.   In   it   we   override   the   protected   method   ofInit()   and   define   various   style   elements   for   our   component   with   the   objective   that   the   web   developer   using   this   control   will   have   total   say   on   how   the   control   looks.    
   
  The   properties   we   add   to   the   control   include   oneBehaviorURI   and   one   ServiceURI,   which   enable   the   control   user   to   specify   the   URL   of   thewebservice.htc   file   on   the   server   and   the   URI   of   the   webservice.   We,   then,   go   on   to   instantiate   new   TableCell   elements   from   the   Framework,   setting   them   with   all   the   variables   containing   the   css   properties   and   finally   adding   them   to   our   control   -   which   is   a   sub   class   of   the   Table   class.   For   this,   we   must   first   add   the   Table   Cell   into   a   newly   instantiated   TableRow   element   through   its   Cells   Collection   and   the   table   row   should   be   added   to   the   Rows   Collection   of   our   control.   Then,   the   client   side   scripts   are   all   written   into   a   string   variable   called   Doc.   An   easy   way   of   adding   any   script   to   the   output   document   is   to   use   theWrite   Method   of   theHtmlTextWriter   Object   given   to   us   when   we   override   theRender   Method.   Therefore,   to   do   the   writing,   we   store   the   entire   script   block   in   thisDoc   variable.  
   
  Finally   we   override   the   Render   method   of   the   Table   class   and   write   the   scripts   on   to   the   client   browser   using   theHtmlTextWriter   object   handed   over   to   us   by   this   method.   We   should   not   forget   to   call   the   base   class'sRender   Method,   lest   all   our   initialization   code   is   left   out   of   the   page.    
   
  The   Control   thus   created   is   used   in   any   ASP.NET   web   form   by   inserting   the   following   code:   (You   may   change   the   URIs   according   to   your   server   settings)  
   
   
   
   
   
   
   
   
   
   
   
   
   
  When   running   this   application   you   will   see   a   screen   such   as   below   that   you   can   log   on   to   and   interact   on.If   you   get   someone   else   to   log   on   to   the   page   on   to   their   computer   you   can   have   a   conversation:    
   
   
   
  Summary  
  In   this   article   we   saw   how   to   create   a   chat   application   using   ASP.NET.Hopefully   through   this   you   will   see   the   benefits   of   using   ASP.NET   for   this   sort   of   application   and   how   by   doing   this   you   can   avoid   issues   such   as   creating   a   server   side   listener.In   this   application   you   cannot   log   off   yourself,   but   you   can   change   the   timing   that   people   are   logged   on   and   inactive   before   being   disconnected   for   longer   than   two   minutes   in   the   C   sharp   code.This   article   should   help   you   develop   your   own   ASP.NET   chat   applications.  
   
   
   
                          [download   relative   material]Top

4 楼ghghzzzz(ghghzzzz)回复于 2005-01-26 21:58:40 得分 30

http://www.58down.com/soft/214.htmTop

5 楼minghui000(沉迷网络游戏)回复于 2005-01-26 22:46:56 得分 0

另一份  
   
  ///ChatMessage.cs  
  using   System;  
   
  namespace   chat  
  {  
  ///   <summary>  
  ///   ChatMessage类封装了两个string变量:UserLists--用户列表,Messages--要传递的信息  
  ///   </summary>  
  public   class   ChatMessage  
  {  
  public   string   UserList,   Messages;  
  }  
  }  
  第二个我们要建立的是什么呢?一个聊天室应能存储在线成员的名字及访问时间  
  ///Member.cs  
  using   System;  
   
  namespace   chat  
  {  
  ///   <summary>  
  ///   Member类为每个聊天者封装了Server端的变量  
  ///   </summary>  
  public   class   Member  
  {  
  //   存储消息的队列    
  public   string   UserName,   MsgQueue;  
  //   判断滞留事件以便踢人  
  public   System.DateTime   LastAccessTime;  
  //   The   constructor  
  public   Member(string   NickName)  
  {  
  this.UserName=NickName;  
  this.LastAccessTime=DateTime.Now;  
  }  
  }  
  }  
   
  接下来我们就应该做这个asmx了  
  ///ChatWebService.asmx  
  using   System;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Data;  
  using   System.Diagnostics;  
  using   System.Web;  
  using   System.Web.Services;  
   
  namespace   chat  
  {  
  ///   <summary>  
  ///   Summary   description   for   ChatWebService.  
  ///   </summary>  
  [WebService   (Namespace   =   "http://localhost/chat/",   Description   =   "This   service   provides   an   chat   service")]  
  public   class   ChatWebService   :   System.Web.Services.WebService  
  {  
  public   ChatWebService()  
  {  
  //CODEGEN:   This   call   is   required   by   the   ASP.NET   Web   Services   Designer  
  InitializeComponent();  
  }  
   
  #region   Component   Designer   generated   code  
  ///   <summary>  
  ///   Required   method   for   Designer   support   -   do   not   modify  
  ///   the   contents   of   this   method   with   the   code   editor.  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  }  
  #endregion  
   
  ///   <summary>  
  ///   Clean   up   any   resources   being   used.  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  }  
   
  [WebMethod(Description="接收用户名作为参数存储到Application对象中")]  
  public   string   Login(string   username)  
  {  
  //   Ascertain   that   all   the   registered   chat   participants   are   active  
  CheckMembersList();  
  //   Synchronization   Lock  
  Application.Lock();  
  //   Get   the   collection   of   keys   for   the   Application   Variables  
  String[]   Members   =   Application.AllKeys;  
  //   Are   there   any   registered   chat   members?   &   the   present   request   is   for   a   unique   nick   name?  
  if   ((Members.Length>0)&&(Array.IndexOf(Members,username)>-1))  
  {  
  throw   new   Exception("该用户已存在!");  
  }  
  //   Create   a   new   Member   object   for   this   participant  
  Member   NewMember   =   new   Member(username);  
  //   Add   this   new   member   to   the   collectionof   Application   Level   Variables  
  Application.Add(username,   NewMember);  
  //   Synchronization   unlock  
  Application.UnLock();  
  //   Go   and   get   the   list   of   current   chat   participants   and   retrun   the   list  
  return   GetMembersList();  
  }  
   
  [WebMethod(Description="GetMsg方法用用户名和消息为参数返回一个ChatMessage对象,包括要传递的消息和用户列表")]  
  public   ChatMessage   XchangeMsgs(string   username,   string   Msg)  
  {  
  //   Ascertain   that   all   the   registered   chat   participants   are   active  
  CheckMembersList();  
  //   Synchronization   Lock  
  Application.Lock();  
  //   Get   the   collection   of   keys   for   the   Application   Variables  
  String[]   Members   =   Application.AllKeys;  
  if   ((Members.Length==0)||(Array.IndexOf(Members,username)==-1))  
  //   Are   there   any   registered   chat   members?   &   the   present   request   is   for   a   unique   nick   name?  
  {  
  throw   new   Exception("你当前可能没有登陆或登陆超时,请重新登陆!");  
  }  
  ChatMessage   RetMsg   =   new   ChatMessage();  
   
  RetMsg.UserList   =   GetMembersList();  
  //   Loop   through   all   the   Chat   Participant's   serverside   Member   Objects   and  
  //   add   the   message   just   received   in   their   waiting   message   queue  
  for   (int   x=0;x<Members.Length;x++)  
  {  
  Member   temp   =   (Member)Application[Members[x]];  
  temp.MsgQueue+=("<BR><Font   color   =   Red>"   +   username   +   "   说:<BR></FONT><Font   color   =   Blue>"   +   Msg);  
  if   (temp.UserName   ==   username)  
  {  
  RetMsg.Messages   =   temp.MsgQueue;  
  temp.MsgQueue="";  
  temp.LastAccessTime=DateTime.Now;  
  }  
  }  
  //   Synchronization   unlock  
  Application.UnLock();  
  return   RetMsg;  
  }  
   
  [WebMethod(Description="GetMsg方法用username为参数返回一个ChatMessage对象,包括要传递的消息和用户列表")]  
  public   ChatMessage   GetMsgs(string   username)  
  {  
  Application.Lock();  
  CheckMembersList();  
  Application.Lock();  
  String[]   Members   =   Application.AllKeys;  
  if   ((Members.Length==0)||(Array.IndexOf(Members,username)==-1))  
  {  
  throw   new   Exception("Unknown   User.   Please   Login   with   a   UserName");  
  }  
  ChatMessage   RetMsg   =   new   ChatMessage();  
  RetMsg.UserList   =   GetMembersList();  
  Member   temp   =   (Member)Application[username];  
  RetMsg.Messages   =   temp.MsgQueue;  
  temp.MsgQueue="";  
  temp.LastAccessTime=DateTime.Now;  
  Application.UnLock();  
  return   RetMsg;  
  }  
   
  public   string   GetMembersList()  
  {  
  Application.Lock();  
  String   UserList   =   "";  
  String[]   Members   =   Application.AllKeys;  
  Application.UnLock();  
  for   (int   x=0;x<Members.Length;x++)  
  {  
  Member   temp   =   (Member)Application[Members[x]];  
  UserList   +=   (temp.UserName+"\n");  
  }  
  return   UserList;  
  }  
   
  private   void   CheckMembersList()  
  {  
  String[]   Members   =   Application.AllKeys;  
  ArrayList   RemoveList   =   new   ArrayList();  
  for   (int   x=0;x<Members.Length;x++)    
  {  
  Member   temp   =   (Member)   Application[Members[x]];  
  int   test   =   (DateTime.Now.Subtract(temp.LastAccessTime)).Minutes;  
  if   (test   >   2)  
  {  
  RemoveList.Add(Members[x]);    
  }  
  }  
  //   Users   =   null;  
  for   (int   count   =   0;count<RemoveList.Count;count++)  
  {  
  Application.Remove((String)RemoveList[count]);  
  }  
  return;  
  }  
   
   
  }  
  }    
  Top

6 楼minghui000(沉迷网络游戏)回复于 2005-01-26 22:47:28 得分 0

server   control,先来看一下代码  
  using   System;  
  using   System.Web.UI;  
  using   System.Web.UI.WebControls;  
  using   System.Web.UI.HtmlControls;  
  using   System.ComponentModel;  
   
  namespace   Michael.Web.UI.Controls  
  {  
  ///   <summary>  
  ///   Summary   description   for   chat.  
  ///   </summary>  
  [DefaultProperty("Text"),    
  ToolboxData("<{0}:chat   runat=server></{0}:chat>")]  
  public   class   chat   :   System.Web.UI.WebControls.Table  
  {  
  private   string   doc;  
  private   string   text;  
  [Bindable(true),    
  Category("Appearance"),    
  DefaultValue("")]    
  public   string   Text    
  {  
  get  
  {  
  return   text;  
  }  
   
  set  
  {  
  text   =   value;  
  }  
  }  
   
  ///   <summary>    
  ///   Render   this   control   to   the   output   parameter   specified.  
  ///   </summary>  
  ///   <param   name="output">   The   HTML   writer   to   write   out   to   </param>  
  protected   override   void   Render(HtmlTextWriter   output)  
  {  
  //   The   script   block   is   written   to   the   client  
  output.Write(doc);  
   
  base.Render(output);  
  }  
   
  private   string   Serviceurl   =   "http://localhost/chat/ChatWebService.asmx?WSDL";  
  [Bindable(true),    
  Category("WebServiceProperty"),    
  DefaultValue("http://localhost/chat/ChatWebService.asmx?WSDL")]    
  public   string   ServiceURL  
  {  
  get  
  {  
  return   Serviceurl;  
  }  
  set  
  {  
  Serviceurl   =   value;  
  }  
  }  
  private   string   Behaviorurl   =   "http://localhost/chat/webservice.htc";  
  [Bindable(true),    
  Category("WebServiceProperty"),    
  DefaultValue("")]    
  public   string   BehaviorURL  
  {  
  get  
  {  
  return   Behaviorurl;  
  }  
  set  
  {  
  Behaviorurl   =   value;  
  }  
  }  
   
  private   string   tablecssclass;  
  [Bindable(true),    
  Category("LayoutProperty"),    
  DefaultValue("")]    
  public   string   TableCssClass  
  {  
  get  
  {  
  return   tablecssclass;  
  }  
  set  
  {  
  tablecssclass   =   value;  
  }  
  }  
   
  private   string   titlecssclass;  
  [Bindable(true),    
  Category("LayoutProperty"),    
  DefaultValue("")]    
  public   string   TitleCssClass  
  {  
  get  
  {  
  return   titlecssclass;  
  }  
  set  
  {  
  titlecssclass   =   value;  
  }  
  }  
   
  private   string   onlinecssclass;  
  [Bindable(true),    
  Category("LayoutProperty"),    
  DefaultValue("")]    
  public   string   OnlineCssClass  
  {  
  get  
  {  
  return   onlinecssclass;  
  }  
  set  
  {  
  onlinecssclass   =   value;  
  }  
  }  
   
  private   string   msgcssclass;  
  [Bindable(true),    
  Category("LayoutProperty"),    
  DefaultValue("")]    
  public   string   MSGCssClass  
  {  
  get  
  {  
  return   msgcssclass;  
  }  
  set  
  {  
  msgcssclass   =   value;  
  }  
  }  
   
  private   string   selusercssclass;  
  [Bindable(true),    
  Category("LayoutProperty"),    
  DefaultValue("")]    
  public   string   SelUserCssClass  
  {  
  get  
  {  
  return   selusercssclass;  
  }  
  set  
  {  
  selusercssclass   =   value;  
  }  
  }  
  protected   override   void   OnInit(EventArgs   e)  
  {  
  this.ID   =   "service";  
   
  this.Style["Behavior"]   =   "url('"   +   Behaviorurl   +   "')";  
   
  this.Style["Table-Layout"]   =   "Fixed";  
   
  if(   this.Attributes["class"]   ==   null)   this.Attributes["class"]   =   tablecssclass;  
   
  this.Attributes["onresult"]   =   UniqueID   +   "_onmyresult();";  
   
  TableRow   tr;  
  //   And   also   create   7   Table   Cell   elements   one   by   one  
  TableCell   cell   =   new   TableCell();  
   
  cell.Attributes["class"]   =   titlecssclass;  
  cell.Attributes["Align"]   =   "Left";  
   
  //   Set   the   caption   of   the   control  
  cell.Text   =   "Portal   聊天室";  
  //   Instantiate   a   Table   Roa   and   attach   the   First   Cell   to   it  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  //   Add   the   Table   Row   to   our   Control  
  this.Rows.Add(tr);  
   
  //   Row   No   2   starts   here  
   
  cell   =   new   TableCell();  
   
  cell.Attributes["class"]   =   onlinecssclass;  
  cell.Text   =   "在线人员";  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  this.Rows.Add(tr);  
   
  //   Row   No   3   Starts   here  
   
  cell   =   new   TableCell();  
  cell.Style["Height"]   =   "25%";  
  //   We   create   a   DIV   element   using   HtmlGenericControl   object  
  //   We   can   also   do   this   using   the   Panel   object  
  HtmlGenericControl   d   =   new   HtmlGenericControl("Div");  
  d.ID   =   UniqueID   +   "_ChatMsgs";  
  d.Style["Height"]   =   "100%";  
  d.Style["Width"]   =   "100%";  
  d.Style["Overflow"]   =   "Auto";  
  d.Style["Padding-Left"]   =   "15%";  
  d.ID   =   UniqueID   +   "_ChatList";  
  //   Adding   the   DIV   element   to   the   Table   Cell  
  cell.Controls.Add(d);  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  this.Rows.Add(tr);  
   
  Top

7 楼minghui000(沉迷网络游戏)回复于 2005-01-26 22:48:14 得分 0

//   Row   No   4   Starts   here  
   
  cell   =   new   TableCell();  
   
  cell.Attributes["class"]   =   msgcssclass;  
  cell.Text   =   "消息:";  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  this.Rows.Add(tr);  
   
  //   Row   No   5   starts   here  
   
  cell   =   new   TableCell();  
  cell.Style["Height"]   =   "35%";  
  d   =   new   HtmlGenericControl("Div");  
  d.ID   =   UniqueID   +   "_ChatMsgs";  
  d.Style["Height"]   =   "100%";  
  d.Style["Width"]   =   "100%";  
  d.Style["Overflow"]   =   "Auto";  
  cell.Controls.Add(d);  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  this.Rows.Add(tr);  
   
  //   Row   No   6   Starts   here  
   
  cell   =   new   TableCell();  
   
  cell.Attributes["class"]   =   selusercssclass;  
  cell.ID   =   UniqueID   +   "_Prompt";  
  cell.Text   =   "选择一个用户:";  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  this.Rows.Add(tr);  
   
  //   Row   No   7   starts   here  
   
  cell   =   new   TableCell();  
  cell.Text   =   "<INPUT   Type=\"Text\"   id=   '"   +   UniqueID   +   "_UserInput'>   \r\n";  
  cell.Text   +=   "<BR>\r\n";  
  cell.Text   +=   "<Button   id   =   '"   +   UniqueID   +   "_bnSendMsg'   onclick   =   \"return   SendMsg();\"   class   =   "   +   UniqueID   +   "_TitleLabel   style   =   \"display:none\">   发送   </Button>\r\n";  
  cell.Text   +=   "<Button   id   =   '"   +   UniqueID   +   "_bnSelectName'   onclick   =   \"return   "   +   UniqueID   +   "_SelectName();\"   class   =   "   +   UniqueID   +   "_TitleLabel   style   =   \"display:block\">   登陆   </Button>   \r\n";  
  cell.Style["Color"]   =   "Black";  
  cell.Style["Background-Color"]   =   "Gainsboro";  
  tr   =   new   TableRow();  
  tr.Cells.Add(cell);  
  this.Rows.Add(tr);  
   
  //   First   script   Block   is   written   into   'doc'   variable  
   
  doc   =   "\r\n<SCRIPT   FOR   =   'window'   EVENT   =   'onload()'>";    
  doc   +=   "//alert(\"done\");   \r\n";  
  doc   +=   "service.use(\"";  
  doc   +=   Serviceurl   +   "\",\"ChatWebService\");   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.focus();\r\n";  
  doc   +=   "</SCRIPT>   \r\n";  
   
  //   Then   the   second   script   block   follows  
   
  doc   +=   "<script   language=\"JavaScript\">\r\n";  
  doc   +=   "var   "   +   UniqueID   +   "_iCallID1,   "   +   UniqueID   +   "_iCallID2,   "   +   UniqueID   +   "_iCallID3;   \r\n";  
  doc   +=   "var   "   +   UniqueID   +   "_NickName;   \r\n";  
  doc   +=   "var   "   +   UniqueID   +   "_MsgXML   =   new   ActiveXObject(\"MSXML.DOMDocument\");\r\n";  
  doc   +=   "function   "   +   UniqueID   +   "_SelectName()   \r\n";  
  doc   +=   "{   \r\n";  
  doc   +=   "if   ("   +   UniqueID   +   "_UserInput.value   ==   \"\")   return   false;\r\n";  
  doc   +=   ""   +   UniqueID   +   "_NickName   =   "   +   UniqueID   +   "_UserInput.value;   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_bnSelectName.disabled   =   'true';   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.disabled   =   'true';\r\n";  
  doc   +=   ""   +   UniqueID   +   "_iCallID1   =   service.ChatWebService.call(\"Login\","   +   UniqueID   +   "_NickName);   \r\n";  
  doc   +=   "}   \r\n";  
  doc   +=   "function   "   +   UniqueID   +   "_onmyresult()   \r\n";  
  doc   +=   "{   \r\n";  
  doc   +=   "if((event.result.error)&&("   +   UniqueID   +   "_iCallID1==event.result.id))   \r\n";  
  doc   +=   "{   \r\n";  
  doc   +=   "var   xfaultcode   =   event.result.errorDetail.code;   \r\n";  
  doc   +=   "var   xfaultstring   =   event.result.errorDetail.string;   \r\n";  
  doc   +=   "var   xfaultsoap   =   event.result.errorDetail.raw;\r\n";  
  doc   +=   "\r\n";  
  doc   +=   "//   Add   code   to   output   error   information   here\r\n";  
  doc   +=   "alert(xfaultstring);\r\n";  
  doc   +=   ""   +   UniqueID   +   "_bnSelectName.disabled   =   false;\r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.disabled   =   false;   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.focus();\r\n";  
  doc   +=   "\r\n";  
  doc   +=   "}   \r\n";  
  doc   +=   "else   if((!event.result.error)&&("   +   UniqueID   +   "_iCallID1==event.result.id))   \r\n";  
  doc   +=   "{   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_ChatList.innerText=   event.result.value;   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_ChatList.scrollTop   =   2000;   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_bnSelectName.style.display   =   'none';\r\n";  
  doc   +=   ""   +   UniqueID   +   "_bnSendMsg.style.display   =   'block';\r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.value   =   \"\";   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.disabled   =   false;   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.focus();\r\n";  
  doc   +=   ""   +   UniqueID   +   "_Prompt.innerText   =   "   +   UniqueID   +   "_NickName   +   \"   说:\";   \r\n";  
  doc   +=   "window.setTimeout('"   +   UniqueID   +   "_iCallID2   =   service.ChatWebService.call(\"GetMsgs\","   +   UniqueID   +   "_NickName);',3000);   \r\n";  
  doc   +=   "}   \r\n";  
  doc   +=   "else   if((event.result.error)&&("   +   UniqueID   +   "_iCallID2==event.result.id))\r\n";  
  doc   +=   "   {\r\n";  
  doc   +=   "var   xfaultcode   =   event.result.errorDetail.code;   \r\n";  
  doc   +=   "var   xfaultstring   =   event.result.errorDetail.string;   \r\n";  
  doc   +=   "var   xfaultsoap   =   event.result.errorDetail.raw;\r\n";  
  doc   +=   "//   Add   code   to   output   error   information   here\r\n";  
  doc   +=   "alert(\"xfaultstring\");\r\n";  
  doc   +=   "   }\r\n";  
  doc   +=   "   else   if((!event.result.error)&&("   +   UniqueID   +   "_iCallID2==event.result.id))\r\n";  
  doc   +=   "   {\r\n";  
  doc   +=   "var   xmlResult   =   event.result.raw.xml;   \r\n";  
  doc   +=   "   if   (xmlResult   !=   \"\"   &&   xmlResult   !=   null)\r\n";  
  doc   +=   "   {\r\n";  
  doc   +=   "\r\n";  
  doc   +=   ""   +   UniqueID   +   "_MsgXML.loadXML(xmlResult);\r\n";  
  doc   +=   "   "   +   UniqueID   +   "_ChatList.innerText   =   "   +   UniqueID   +   "_MsgXML.selectSingleNode(\"//UserList\").text;   \r\n";  
  doc   +=   ""   +   UniqueID   +   "_ChatList.scrollTop   =   2000;   \r\n";  
  doc   +=   "   "   +   UniqueID   +   "_ChatMsgs.innerHTML   +=   "   +   UniqueID   +   "_MsgXML.selectSingleNode(\"//Messages\").text;\r\n";  
  doc   +=   ""   +   UniqueID   +   "_ChatMsgs.scrollTop   =   2000;   \r\n";  
  doc   +=   "   }\r\n";  
  doc   +=   "   window.setTimeout('"   +   UniqueID   +   "_iCallID2   =   service.ChatWebService.call(\"GetMsgs\","   +   UniqueID   +   "_NickName);',3000);\r\n";  
  doc   +=   "   }\r\n";  
  doc   +=   "else   if((event.result.error)&&("   +   UniqueID   +   "_iCallID3==event.result.id))\r\n";  
  doc   +=   "   {\r\n";  
  doc   +=   "var   xfaultcode   =   event.result.errorDetail.code;   \r\n";  
  doc   +=   "var   xfaultstring   =   event.result.errorDetail.string;   \r\n";  
  doc   +=   "var   xfaultsoap   =   event.result.errorDetail.raw;\r\n";  
  doc   +=   "//   Add   code   to   output   error   information   here\r\n";  
  doc   +=   "alert(\"xfaultstring\");\r\n";  
  doc   +=   "   }\r\n";  
  doc   +=   "   else   if((!event.result.error)&&("   +   UniqueID   +   "_iCallID3==event.result.id))\r\n";  
  doc   +=   "   {\r\n";  
  doc   +=   "var   xmlResult   =   event.result.raw.xml;   \r\n";  
  doc   +=   "   if   (xmlResult   !=   \"\"   &&   xmlResult   !=   null)\r\n";  
  doc   +=   "   {\r\n";  
  doc   +=   "\r\n";  
  doc   +=   ""   +   UniqueID   +   "_MsgXML.loadXML(xmlResult);\r\n";  
  doc   +=   "   "   +   UniqueID   +   "_ChatList.innerText   =   "   +   UniqueID   +   "_MsgXML.selectSingleNode(\"//UserList\").text;   \r\n";  
  doc   +=   "   "   +   UniqueID   +   "_ChatMsgs.innerHTML   +=   "   +   UniqueID   +   "_MsgXML.selectSingleNode(\"//Messages\").text;\r\n";  
  doc   +=   "   "   +   UniqueID   +   "_ChatList.scrollTop   =   2000;   \r\n";  
  doc   +=   "   "   +   UniqueID   +   "_bnSendMsg.disabled   =   false;\r\n";  
  doc   +=   "   "   +   UniqueID   +   "_ChatMsgs.scrollTop   =   2000;   \r\n";  
  doc   +=   "   "   +   UniqueID   +   "_UserInput.value   =   \"\";\r\n";  
  doc   +=   "   "   +   UniqueID   +   "_UserInput.disabled   =   false;\r\n";  
  doc   +=   "   "   +   UniqueID   +   "_UserInput.focus();\r\n";  
  doc   +=   "   }\r\n";  
  doc   +=   "   window.setTimeout('"   +   UniqueID   +   "_iCallID2   =   service.ChatWebService.call(\"GetMsgs\","   +   UniqueID   +   "_NickName);',3000);\r\n";  
  doc   +=   "   }\r\n";  
  doc   +=   "}   \r\n";  
  doc   +=   "function   SendMsg()\r\n";  
  doc   +=   "{   \r\n";  
  doc   +=   "if   ("   +   UniqueID   +   "_UserInput.value   ==   \"\")   return   false;\r\n";  
  doc   +=   ""   +   UniqueID   +   "_bnSendMsg.disabled   =   'true';\r\n";  
  doc   +=   ""   +   UniqueID   +   "_UserInput.disabled   =   'true';\r\n";  
  doc   +=   ""   +   UniqueID   +   "_iCallID3   =   service.ChatWebService.call(\"XchangeMsgs\","   +   UniqueID   +   "_NickName,"   +   UniqueID   +   "_UserInput.value);\r\n";  
  doc   +=   "}   \r\n";  
  doc   +=   "</script>   \r\n";  
   
  }  
  }  
  }  
   
  Top

相关问题

  • 急需asp语音聊天室源码!!!
  • 求.net聊天室源码 谢谢
  • 有哪个源码比较适合学习ASP。NET的~
  • 请给于聊天室或论谈的ASP源码?
  • ASP源码曝光,SOS!
  • 请发asp源码给我!
  • 求OA系统源码或下载地址,.NET或ASP 开发(100)
  • 哪位高人能提供几个ASP聊天室的源码啊~~~
  • 关于ASP。NET生成静态的问题(急需要源码,如果没有源码,介绍得越详细越好)
  • 在ASP。NET中有没有读取RSS的类,哪位知道能否给些源码

关键词

  • asp.net
  • cell
  • 聊天
  • chatwebservice
  • chatmessage
  • chat
  • behaviorurl
  • layoutproperty
  • onlinecssclass
  • tablecssclass

得分解答快速导航

  • 帖主:toshi315
  • minghui000
  • ghghzzzz

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo