0

~/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" />
4

1 回答 1

0

如果您想更改代码,解决问题的简单方法可能是......

//Javascript function
function Open()
{
   var ddl = document.getElementbyId('<%= lstRooms.ClientID%>');
   var ddlvalue = ddl.options[ddl.selectedIndex].value;
   Window.Open("Chat.aspx?rid=" + ddlvalue );
}

删除页面加载中的所有 JS 代码并将其放在 aspx 页面上。让我知道它是否解决了

于 2012-05-01T10:35:44.990 回答