I am writing a chat. Chat arranged using two frames. In one frame displays a list of messages. Another frame contains a textbox to send messages to the database. I can not figure out how to display a list of chat messages? Do I need to use a specific control? That's what I did, but maybe I did it stupidly. I output the text to a div element. But after each message sending, the previous message is erased by the current one. I can not figure out how to make sure that previous messages are not erased. Or maybe my way of displaying chat messages is not correct. If so, how to do it? I bring my code, what I got. Thanks in advance for your help.
Here is the markup from asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Messages.aspx.cs" Inherits="webchat.Messages" %> <!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> <meta http-equiv="refresh" content="5"/> </head> <body> <form id="form1" runat="server"> <div id="chatMenu" runat="server"> </div> </form> </body> </html> 

C # code

 public partial class Messages : System.Web.UI.Page { public static string chatMessage = string.Empty;//временная переменная для хранения сообщения чата protected void Page_Load(object sender, EventArgs e) { Message message = new Message(); message.ReadFromDataBase();//считываем сообщения из БД чата if (message.ReceivedDate != Convert.ToDateTime("01.01.0001 0:00:00") && message.ReceivedMessage != null)//Если строка из БД с сообщением не пустая, выводим сообщение { chatMessage = string.Empty; chatMenu.InnerHtml = string.Format("{0}: {1}", message.ReceivedDate, message.ReceivedMessage);//записываем сообщение в div тег с id chatMenu chatMessage = string.Format("{0}: {1} <br />", message.ReceivedDate, message.ReceivedMessage);//записываем сообщение во временную переменное } else//Иначе выводим текущее сообщение. Если отсутсвует эта строка, после каждого обновления страницы будет выводится пустое сообщение { chatMenu.InnerHtml = chatMessage; } message.DeleteMessageFromDb();//Удаляем строку с сообщением } 

    1 answer 1

     chatMenu.InnerHtml += string.Format("{0}: {1}<br /> ", message.ReceivedDate, message.ReceivedMessage); 

    This is about erasing messages. And, probably, the form can be removed, and hang ajax , which will send a new message to the .aspx page and display them. I hope how to transfer the variable to js ? I will remind: сs :

     public string test = "HashCode"; 

    html/js :

     <script> alert('<%=test %>') </script> 

    No components are needed, just need to be properly laid out, well, beautiful.