c#asp.net发送邮件问题

时间:2022-07-17 03:44:36

I have create one web application where user can send friend request. If there are two users A and B. If A user send friend request to B then one pop up display's on B user dashboard. In that pop up box two buttons are there confirm or ignore.

我创建了一个用户可以发送好友请求的Web应用程序。如果有两个用户A和B.如果用户向B发送好友请求,则在B用户仪表板上弹出一个显示。在弹出框中,有两个按钮确认或忽略。

If user click on confirm button then it takes some time to close that popup box. Because in backgroud it execute code for send email. Once email sent then that popup box close. So I want to close that popup box immediately after clicking on confirm button and then after send mail to that user.

如果用户单击确认按钮,则关闭该弹出框需要一些时间。因为在backgroud中它执行发送电子邮件的代码。一旦发送电子邮件,然后该弹出框关闭。所以我想在点击确认按钮后立即关闭该弹出框,然后在向该用户发送邮件后关闭该弹出框。

Here is my code for accepting request and sending mail

这是我接受请求和发送邮件的代码

#region dlUserFriendRequests_ItemCommand
    protected void dlUserFriendRequests_ItemCommand(object source, DataListCommandEventArgs e)
    {
        HtmlTable objDataTable;
        //Panel objDataTable;
        switch (e.CommandName)
        {
            case "confirm":
                RadioButtonList objRadioButtonList;
                int intFriendRelationID = -1;
                objRadioButtonList = (RadioButtonList)e.Item.FindControl("rblstFriends");

                if (objRadioButtonList != null)
                {
                    intFriendRelationID = UserManagementBL.AcceptUserFriendRequest(Convert.ToInt32(e.CommandArgument), this.LoginSessionDO.UserID, objRadioButtonList.SelectedItem.Text);

                    if (intFriendRelationID > 0)
                    {
                        int SentByUserID = Convert.ToInt32(e.CommandArgument);
                        DataTable dtbSenderdetails = null;
                        string SenderEmail = "";

                        dtbSenderdetails = UserManagementBL.GetUserDetails(SentByUserID);
                        if (dtbSenderdetails != null)
                        {
                            SenderEmail = dtbSenderdetails.Rows[0]["UserName"].ToString();
                            SendConfirmationMail(SenderEmail);
                            Response.Redirect("~/Dashboard/Dashboard.aspx",false);                                
                            //GetUserFriendRequests();
                        }
                    }
                }
              break;    

              case "Ignore":
                int intFriendRequestID = -1;
                intFriendRequestID = UserManagementBL.IgnoreUserFriendRequest(Convert.ToInt32(e.CommandArgument), this.LoginSessionDO.UserID);
                GetUserFriendRequests();
                break;
        }
   }
        #endregion

 #region Send confirmation mail
    public void SendConfirmationMail(string email)
    {
        //DataTable dtblUserDetails = UserManagementBL.GetUserByUserName(email);
        //if (dtblUserDetails != null)
        //{
            //int UserID = Convert.ToInt32(dtblUserDetails.Rows[0]["UserID"]);

            //string FirstName = Convert.ToString(dtblUserDetails.Rows[0]["FirstName"]);
            //string LastName = Convert.ToString(dtblUserDetails.Rows[0]["LastName"]);
            string FirstName = this.LoginSessionDO.FirstName;
            string LastName = this.LoginSessionDO.LastName;

            var parameters = new System.Collections.Generic.Dictionary<string, string>();
            parameters.Add("USER_NAME", string.Format("{0} {1}", FirstName, LastName));


            parameters.Add("USER_IMAGE_URL", string.Format(SystemConfiguration.GetSiteURL() + "UserControls/UserPhoto.ashx?UserID={0}", this.LoginSessionDO.UserID));

            string ToAddress = email;
            string subject = FirstName + "  " + LastName + " confirmed you as a friend on Lifetrons.";

            CommonFunctions.CommonFunctions.SendEmail(SystemConfiguration.GetEmailSenderAddress(), ToAddress, subject, CommonFunctions.EmailTemplates.AcceptFriendRequest, parameters);
        //}
    }
    #endregion

Here is my pop up box image c#asp.net发送邮件问题

这是我的弹出框图像

So how can I close that pop up box immediately after confirm button click? Is there any changes in my code?

那么如何在确认按钮点击后立即关闭该弹出框?我的代码有变化吗?

1 个解决方案

#1


1  

You would do this in JavaScript. I assume you're already using AJAX to perform the Confirm action, otherwise it would just be reloading the page and your popup shouldn't be there anyway (since they're already confirmed?).

你会用JavaScript做到这一点。我假设你已经在使用AJAX来执行Confirm操作,否则它只是重新加载页面而且你的弹出窗口不应该在那里(因为它们已经被确认了?)。

If you have jQuery on the frontend, you can use:

如果你在前端有jQuery,你可以使用:

$('#confirm-box-id').hide();

Without jQuery, you could use:

没有jQuery,你可以使用:

document.getElementById('confirm-box-id').style.display = 'none';

Re-reading your message, it seems this is just a long running action. You should note that if you do hide this and don't show any indication of progress using the code above, for example, your user may navigate away or close the browser, which may cause the action to stop processing or be terminated forcefully server-side so the confirmation would never happen.

重新阅读你的消息,这似乎只是一个长期的行动。您应该注意,如果您确实隐藏了此信息,并且未使用上述代码显示任何进度指示,例如,您的用户可能会离开或关闭浏览器,这可能导致操作停止处理或被强制终止服务器 - 所以确认永远不会发生。

#1


1  

You would do this in JavaScript. I assume you're already using AJAX to perform the Confirm action, otherwise it would just be reloading the page and your popup shouldn't be there anyway (since they're already confirmed?).

你会用JavaScript做到这一点。我假设你已经在使用AJAX来执行Confirm操作,否则它只是重新加载页面而且你的弹出窗口不应该在那里(因为它们已经被确认了?)。

If you have jQuery on the frontend, you can use:

如果你在前端有jQuery,你可以使用:

$('#confirm-box-id').hide();

Without jQuery, you could use:

没有jQuery,你可以使用:

document.getElementById('confirm-box-id').style.display = 'none';

Re-reading your message, it seems this is just a long running action. You should note that if you do hide this and don't show any indication of progress using the code above, for example, your user may navigate away or close the browser, which may cause the action to stop processing or be terminated forcefully server-side so the confirmation would never happen.

重新阅读你的消息,这似乎只是一个长期的行动。您应该注意,如果您确实隐藏了此信息,并且未使用上述代码显示任何进度指示,例如,您的用户可能会离开或关闭浏览器,这可能导致操作停止处理或被强制终止服务器 - 所以确认永远不会发生。