c#asp.net发送邮件问题
我已经创建了一个web应用程序,用户可以在其中发送好友请求。如果有两个用户A和B。如果A用户向B发送好友请求,则B用户仪表板上将显示一个弹出窗口。在弹出框中有两个按钮确认或忽略 如果用户单击确认按钮,则关闭弹出框需要一些时间。因为它在后台执行发送电子邮件的代码。一旦发送电子邮件,弹出框就会关闭。因此,我想在单击“确认”按钮后立即关闭弹出框,然后在向该用户发送邮件后关闭弹出框 这是我接受请求和发送邮件的代码c#asp.net发送邮件问题,c#,asp.net,popup,C#,Asp.net,Popup,我已经创建了一个web应用程序,用户可以在其中发送好友请求。如果有两个用户A和B。如果A用户向B发送好友请求,则B用户仪表板上将显示一个弹出窗口。在弹出框中有两个按钮确认或忽略 如果用户单击确认按钮,则关闭弹出框需要一些时间。因为它在后台执行发送电子邮件的代码。一旦发送电子邮件,弹出框就会关闭。因此,我想在单击“确认”按钮后立即关闭弹出框,然后在向该用户发送邮件后关闭弹出框 这是我接受请求和发送邮件的代码 #region dlUserFriendRequests_ItemCommand
#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
#区域dlUserFriendRequests_ItemCommand
受保护的无效dlUserFriendRequests\u ItemCommand(对象源,DataListCommandEventArgs e)
{
HtmlTable对象数据表;
//面板对象数据库;
开关(例如CommandName)
{
案例“确认”:
RadioButtonlistobjradioButtonlist;
int intFriendRelationID=-1;
objRadioButtonList=(RadioButtonList)e.Item.FindControl(“rblstFriends”);
if(objRadioButtonList!=null)
{
intFriendRelationID=UserManagementBL.AcceptUserFriendRequest(Convert.ToInt32(e.CommandArgument),this.LoginSessionDO.UserID,objradioButtoList.SelectedItem.Text);
如果(intFriendRelationID>0)
{
int SentByUserID=Convert.ToInt32(e.CommandArgument);
数据表dtbSenderdetails=null;
字符串SenderEmail=“”;
dtbSenderdetails=UserManagementBL.GetUserDetails(SentByUserID);
如果(dtbSenderdetails!=null)
{
SenderEmail=dtbSenderdetails.Rows[0][“UserName”].ToString();
发送确认邮件(SenderEmail);
Response.Redirect(“~/Dashboard/Dashboard.aspx”,false);
//GetUserFriendRequests();
}
}
}
打破
案例“忽略”:
int intFriendRequestID=-1;
intFriendRequestID=UserManagementBL.IgnoreUserFriendRequest(Convert.ToInt32(e.CommandArgument),this.LoginSessionDO.UserID);
GetUserFriendRequests();
打破
}
}
#端区
#地区发送确认邮件
公共无效发送确认邮件(字符串电子邮件)
{
//DataTable DTBluerDetails=UserManagementBL.GetUserByUserName(电子邮件);
//if(dtbluerdetails!=null)
//{
//int UserID=Convert.ToInt32(dtbluerdetails.Rows[0][“UserID]”);
//string FirstName=Convert.ToString(dtbluerdetails.Rows[0][“FirstName]”);
//字符串LastName=Convert.ToString(dtbluerdetails.Rows[0][“LastName]”);
string FirstName=this.LoginSessionDO.FirstName;
字符串LastName=this.LoginSessionDO.LastName;
var参数=new System.Collections.Generic.Dictionary();
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));
字符串ToAddress=电子邮件;
字符串subject=FirstName+“”+LastName+“确认您是Lifetrons上的朋友。”;
CommonFunctions.CommonFunctions.SendEmail(系统配置.GetEmailSenderAddress(),ToAddress,主题,CommonFunctions.EmailTemplates.AcceptFriendRequest,参数);
//}
}
#端区
这是我的弹出框图片
那么,如何在单击确认按钮后立即关闭弹出框?我的代码有什么变化吗 您可以在JavaScript中执行此操作。我假设您已经在使用AJAX执行
Confirm
操作,否则它只是重新加载页面,您的弹出窗口无论如何都不应该出现(因为它们已经被确认了?)
如果前端有jQuery,可以使用:
$('#confirm-box-id').hide();
如果没有jQuery,您可以使用:
document.getElementById('confirm-box-id').style.display = 'none';
重新阅读你的信息,这似乎只是一个长期运行的行动。您应该注意,如果您确实使用上述代码隐藏此操作,并且没有显示任何进度指示,例如,您的用户可能会导航到别处或关闭浏览器,这可能会导致操作停止处理或在服务器端强制终止,因此确认不会发生。您可以使用JavaScript执行此操作。我假设您已经在使用AJAX执行
Confirm
操作,否则它只是重新加载页面,您的弹出窗口无论如何都不应该出现(因为它们已经被确认了?)
如果前端有jQuery,可以使用:
$('#confirm-box-id').hide();
如果没有jQuery,您可以使用:
document.getElementById('confirm-box-id').style.display = 'none';
重新阅读你的信息,这似乎只是一个长期运行的行动。您应该注意,如果您确实使用上述代码隐藏此操作,并且没有显示任何进度指示,例如,您的用户可能会导航到别处或关闭浏览器,这可能会导致操作停止处理或在服务器端强制终止,这样确认就永远不会发生。@感谢您回答“是”,这是一个很长的操作。您是对的,用户可以导航到另一个选项卡或页面此处我用于弹出@Ajay好的,您是否在弹出窗口运行时尝试了我的代码来关闭弹出窗口?我不知道我将该查询放在哪里了?@Ajay在您的前端代码中,找到“确认”按钮并在其上指定一个单击处理程序来调用此代码。@谢谢您的回复是的,这是一个很长的操作。您是对的,用户可以导航到