|
|
|
 |
 |
Исходник |
 |
|
 |
 |
|
Автор:
|
|
|
Название:
|
Чат с AJAX |
|
Дата:
|
28 July 2007 |
|
Описание: |
простейший чат, но зато полностью на ajax |
| |
Разместить ссылку на этот исходник в форуме вы можете вставив в текст сообщения
следующую строку:
[CODEPOST ID=209]Чат с AJAX[/CODEPOST] |
| Оценка: |
Проголосовало 10 посетителей, средняя оценка 4.20 |
| Оценить: |
|
1 Default.aspx:
2
3 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
4
5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml">
7 <head runat="server">
8 <title>Типа чат</title>
9 </head>
10 <script language="javascript">
11 function Func()
12 {
13 document.form1.TextBox3.value='';
14 document.form1.TextBox3.focus();
15 }
16 </script>
17 <body>
18 <form id="form1" runat="server">
19 <asp:ScriptManager ID="ScriptManager1" runat="server" />
20 <div>
21 <table width="100%" border="1">
22 <tr>
23 <td align="right">
24 Клиент:
25 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
26 </tr>
27 <tr>
28 <td align="center">
29 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
30 <ContentTemplate>
31 <asp:TextBox ID="TextBox2" runat="server" Height="200pt" TextMode="MultiLine" Width="100%" />
32 <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick" />
33 </ContentTemplate>
34 <Triggers>
35 <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
36 </Triggers>
37 </asp:UpdatePanel>
38 <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
39 <ProgressTemplate>
40 <img src="loading.gif" />Загрузка...
41 </ProgressTemplate>
42 </asp:UpdateProgress>
43 </td>
44 </tr>
45 <tr>
46 <td align="center">
47 <asp:TextBox ID="TextBox3" runat="server" Width="73%" />
48 <asp:Button ID="Button1" runat="server" Text="Панеслася..." Width="25%" OnClick="Button1_Click" />
49 </td>
50 </tr>
51 </table>
52 </div>
53 </form>
54 </body>
55 </html>
56
57 Default.aspx.cs:
58
59 using System;
60 using System.Data;
61 using System.Configuration;
62 using System.Web;
63 using System.Web.Security;
64 using System.Web.UI;
65 using System.Web.UI.WebControls;
66 using System.Web.UI.WebControls.WebParts;
67 using System.Web.UI.HtmlControls;
68
69 public partial class _Default : System.Web.UI.Page
70 {
71 protected void Page_Load(object sender, EventArgs e)
72 {
73 //Application["messages"] = null;
74 if (Application["messages"] == null) Application["messages"] = "";
75 Button1.Attributes.Add("onclick", "window.setTimeout('Func()',50)");
76 //TextBox2.Attributes.Add("onload", "document.form1.TextBox2.tabIndex=document.form1.TextBox2.rows");
77 }
78 protected void Button1_Click(object sender, EventArgs e)
79 {
80 string mes = TextBox1.Text + " >> " + TextBox3.Text + "\r\n";
81 if (Application["messages"] == null)
82 {
83 Application["messages"] = mes;
84 }
85 else
86 {
87 Application["messages"] = mes + ((string)Application["messages"]);
88 }
89 TextBox2.Text = Application["messages"].ToString();
90 }
91 protected void Timer1_Tick(object sender, EventArgs e)
92 {
93 TextBox2.Text = Application["messages"].ToString();
94 }
95 }
96
97 примерно опробывать можно здесь(не гарантирую что там он будет постоянно, он идет всего-лишь как маленький кусочек от большого сайта):
98 http://sinet-7.iis7.parking.ru |
| Вернуться к списку исходников в категории Общие вопросы программирования на ASP.NET |
|
|
 |
 |
 |
 |
|
|