<!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
<Triggers >
<asp:AsyncPostBackTrigger ControlID ="Button1" EventName ="Click" ></asp:AsyncPostBackTrigger >
</Triggers>
</asp:UpdatePanel>
输入聊天信息:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 选择字体颜色:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>红色</asp:ListItem>
<asp:ListItem>绿色</asp:ListItem>
<asp:ListItem>黄色</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="发送" οnclick="Button1_Click" />
</form>
</body>
</html>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace 综合实例
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Application.Set("Msg", "" + Application["Msg"] + "<br><font color=red size=4>" + Request.UserHostName + "进入聊天室</font>[<font size=2>" + DateTime.Now.ToString() + "</font>]");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Application.Set("Msg", Application["Msg"] + "<br><font color=" + DropDownList1.Text + " size=4>" + Request.UserHostName + "说:" + TextBox1.Text + "</font> [<font size=2>" + DateTime.Now.ToString() + "</font>]");
}
protected void Timer1_Tick(object sender, EventArgs e)
{
try
{
Label1.Text = Application["Msg"].ToString();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}