~/Admin/AdimHome.aspx.cs C# 代码
protected void Page_Load(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language='javascript'>function Open() {");
sb.Append(string.Format("window.open('Chat.aspx?rid={0}'", lstRooms.SelectedValue));
sb.Append(", 'newwindow','toolbar=no,location=no,menubar=no,width=290,height=330,resizable=no,scrollbars=no,top=350,left=980,right=500');return false;");
sb.Append("}</script>");
if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock", sb.ToString());
}
lblFacultyNo.Text = Session["User_Id"].ToString();
lblUserType.Text = Session["User_Type"].ToString();
pnlChat.Visible = false;
}
~/Admin/Chat.aspx.cs 页面C# 代码
protected void Page_Load(object sender, EventArgs e)
{
if (Session["User_Id"] == null)
Response.Redirect("~/Admin/AdimHome.aspx");
if (string.IsNullOrEmpty(Request.QueryString["rid"]))
Response.Redirect("~/Admin/AdminHome.aspx");
txtMsg.Attributes.Add("onkeypress", "return clickButton(event,'btn')");
if (!IsPostBack)
{
hdnRoomID.Value = Request.QueryString["rid"];
ChatRoom room = ChatEngine.GetRoom(hdnRoomID.Value);
string prevMsgs = room.JoinRoom(Session["User_Id"].ToString(), Session["User_Id"].ToString());
txt.Text = prevMsgs;
foreach (string s in room.GetRoomUsersNames())
{
lstMembers.Items.Add(new ListItem(s, s));
}
}
}
想要将lstRooms.SelectedValue传递给Chat.aspx.cs 页面以根据客户请求进行检查以区分他们的聊天室:
sb.Append(string.Format("window.open('Chat.aspx?rid={0}'", lstRooms.SelectedValue));
onclicking btnChat 事件:
<asp:Button ID="btnChat" Runat="server" CssClass="btn" OnClientClick="JavaScript:Open()" OnClick="btnChat_Click" Text="Join Room" />