10-19带表情的聊天室

来源:互联网 发布:js冒泡排序算法 编辑:程序博客网 时间:2024/05/23 16:55

login.aspx

 

<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="昵称:"></asp:Label><asp:TextBox ID="TextBox1"
            runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="转入聊天室..." />
    </div>
    </form>
</body>

login.aspx.cs

  protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text != "")
            {
                Application["Name"] = TextBox1.Text;
                Response.Redirect("聊天.aspx");

            }
            else
            {
                Response.Write("昵称不能为空");
            }
           
        }

聊天.aspx

<body>
    <form id="form1" runat="server">
    <div>
    <table align="center"  >
    <tr><td class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在线聊天</td></tr>
    <tr><td class="style1">
        <asp:TextBox ID="txtChatBox" runat="server" Height="114px" TextMode="MultiLine"
            Width="260px"></asp:TextBox>
        <br />
        <br />
        <div id="aa" runat="server"></div>
        </td>
    </tr>
    <tr>
       <td class="style2"><asp:Label ID="Label1" runat="server" Text="请输入你的信息:"></asp:Label></td>
       <td class="style3">
           <asp:TextBox ID="txtMessage" runat="server" Height="44px" TextMode="MultiLine"
               Width="176px"></asp:TextBox>
           <br />
        </td>
    </tr>
    <tr><td class="style1"><asp:Label ID="Label2" runat="server" Text="选择表情:"></asp:Label></td>
        <td><asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="63px">
            <asp:ListItem>悲伤</asp:ListItem>
            <asp:ListItem>高兴</asp:ListItem>
            <asp:ListItem>大笑</asp:ListItem>
            <asp:ListItem>尴尬</asp:ListItem>
            <asp:ListItem>可爱</asp:ListItem>
            </asp:DropDownList>
            <br />
            <br />
        </td>
     </tr>
     <tr><td class="style1">
        
         <asp:Button ID="btnsend" runat="server" Text="发送信息" onclick="btnsend_Click" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td>
             <asp:Button ID="btnclear" runat="server" Text="清除信息" onclick="btnclear_Click" /></td></tr>    </table>
    </div>
    </form>

聊天.aspx.cs

public partial class 聊天 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                this.txtChatBox.Text = Application["ChatLog"].ToString();
            }
        }

        protected void btnsend_Click(object sender, EventArgs e)
        {

            string a = Application["Name"].ToString();
            if (DropDownList1.SelectedValue == "高兴")
            {
                aa.InnerHtml = a + ":" + this.txtMessage.Text + ":" + "<img src='images/高兴.jpg'>";
            }
            if (DropDownList1.SelectedValue == "大笑")
            {
                aa.InnerHtml = a + ":" + this.txtMessage.Text + ":" + "<img src='images/大笑.jpg'>";
            }
            if (DropDownList1.SelectedValue == "悲伤")
            {
                aa.InnerHtml = a + ":" + this.txtMessage.Text + ":" + "<img src='images/悲伤.jpg'>";
            }


        }

        protected void btnclear_Click(object sender, EventArgs e)
        {
            Application["ChatLog"] = "";
            txtChatBox.Text = Application["ChatLog"].ToString();
        }
    }

效果图:

 

原创粉丝点击