Example #1
0
        protected void ButtonChooseRecipient_Click(object sender, EventArgs e)
        {
            int    otherid   = -1;
            int    currentid = CurrentUser.GetUserId();
            string username;

            // Validate Username
            if (string.IsNullOrWhiteSpace(ReceiverId.Text))
            {
                Msg.Text = "Username entered is empty";
                return;
            }
            else
            {
                otherid  = Authenticate.ConvertUsernameToId(ReceiverId.Text);
                username = ReceiverId.Text;
            }

            // Validate UserID exists
            if (otherid == -1)
            {
                Msg.Text = "No recipient by this username was found";
                return;
            }
            else if (otherid == currentid)
            {
                Msg.Text = "You cannot start a conversation with yourself!";
                return;
            }
            else if (otherid != currentid && otherid > 0)
            {
                ViewState["thisParty"]  = CurrentUser.GetUserId();
                ViewState["otherParty"] = otherid;

                ToggleWindows();
                LblRecipient.Text       = Authenticate.ConvertIdToUsername(otherid);
                ChatRepeater.DataSource = RetrieveMessages(otherid);
                ChatRepeater.DataBind();
                return;
            }
        }