Shekar Raja
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace AJAXORama
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
List<string> messages = new List<string>();
HttpContext.Current.Cache["Messages"] = messages;
}
// other generated code is here...
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class GroupChat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected string GetUserID()
{
string strUserID =
(string) Session["UserID"];
return strUserID;
}
}
и отключите элементы пользовательского интерфейса идентификации пользователя:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class GroupChat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// other code goes here...
void ManageUI()
{
if (GetUserID() == null)
{
// if this is the first request, then get the user’s ID
TextBoxMessage.Enabled = false;
TextBoxConversation.Enabled = false;
ButtonAddYourMessage.Enabled = false;
ButtonSubmitID.Enabled = true;
TextBoxUserID.Enabled = true;
}
else
{
// if this is the first request, then get the user’s ID
TextBoxMessage.Enabled = true;
TextBoxConversation.Enabled = true;
ButtonAddYourMessage.Enabled = true;
ButtonSubmitID.Enabled = false;
TextBoxUserID.Enabled = false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; 494 Part V Dynamic Data, XBAP, MVC, AJAX, and Silverlight
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class GroupChat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// other page code goes here...
protected void ButtonSubmitID_Click(object sender, EventArgs e)
{
Session["UserID"] = TextBoxUserID.Text;
ManageUI();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class GroupChat : System.Web.UI.Page
{
// other page code goes here...
void RefreshConversation()
{
List<string> messages = (List<string>)Cache["Messages"];
if (messages != null)
{
string strConversation = "";
int nMessages = messages.Count;
for(int i = nMessages-1; i >=0; i--)
{
string s;
s = messages[i];
strConversation += s;
strConversation += "\r\n";
}
TextBoxConversation.Text =
strConversation;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class GroupChat : System.Web.UI.Page
{
// Other code goes here...
protected void ButtonAddYourMessage_Click(object sender,
EventArgs e)
{
// Add the message to the conversation...
if (this.TextBoxMessage.Text.Length > 0)
{
List<string> messages = (List<string>)Cache["Messages"];
if (messages != null)
{
TextBoxConversation.Text = "";
string strUserID = GetUserID();
if (strUserID != null)
{
messages.Add(strUserID +
": " +
TextBoxMessage.Text);
RefreshConversation();
TextBoxMessage.Text = "";
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Collections.Generic;
public partial class GroupChat : System.Web.UI.Page
{
// Other code goes here...
protected void Page_Load(object sender, EventArgs e)
{
ManageUI();
RefreshConversation();
}
}</string></string></string></string>