An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
What is the best way to sending mail from gridview check box checked row
I am using gridview and it contains checkboxes.
when i click submit button, i am sending mail to the customer for every checking record.
if i save record without mail, data will be saving more accurate and fast.
But, when i send mail for every records from the gridview, it's taking long time to process it and done.
I know the reason, it will hit smtp server every records and return back is taking time in the server.
What is the alternative way to sending mail while submit the records...
below is my complete code for reference.
protected void Submit_Click(object sender, EventArgs e)
{
try
{
System.Threading.Thread.Sleep(3000);
//After Setting Page Index Loop through its Rows
foreach (GridViewRow gvrow in gbCustomer.Rows)
{
if (gvrow.RowType == DataControlRowType.DataRow)
{
var checkbox = gvrow.FindControl("CheckBox1") as CheckBox;
if (checkbox.Checked)
{
var Id = (gvrow.FindControl("hdnctrlId") as HiddenField).Value;
var CustNo = (gvrow.FindControl("hdnCustNo") as HiddenField).Value;
var CustName = (gvrow.FindControl("hdnCustName") as HiddenField).Value;
var DOJ = (gvrow.FindControl("hdnDOJ") as HiddenField).Value;
//********* Sending Mail
SendMail(Id, CustNo, CustName, DOJ);
//********* Sending Mail
CheckBox chk = (CheckBox)gvrow.FindControl("CheckBox1");
chk.Checked = false;
CheckBox chkAll = (CheckBox)gbCustomer.HeaderRow.FindControl("chkAll");
chkAll.Checked = false;
}
}
}
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Mail Sent successfully.!');window.location.href='NewCustomer.aspx';", true);
}
catch (Exception ex)
{
ErrorMessage.Text = ex.Message;
ErrorMessage.Visible = true;
}
finally
{
}
}
private void SendMail(string Id, string CustNo, string CustName, string DOJ)
{
try
{
FromEmail = "******@biech.com";
ToEmail = "******@biech.com";
if (!string.IsNullOrEmpty(ToEmail))
{
MailMessage mm = new MailMessage(FromEmail, ToEmail);
mm.Subject = "Reg : Customer Request";
string strhtml = "<HTML>";
strhtml += "<body>";
strhtml += "<br>";
strhtml += "<table>";
strhtml += "<tr>";
strhtml += "<td>";
strhtml += "Cust. Name ";
strhtml += "</td>";
strhtml += "<td>";
strhtml += "DOJ. ";
strhtml += "</td>";
strhtml += "<tr><td>";
strhtml += " " + CustName + " </td>";
strhtml += "<td>";
strhtml += " " + DOJ + " </td>";
strhtml += "<br>";
strhtml += "<div align='left'>Regards,</div>";
strhtml += "<div align='left'>Alex Paul</div>";
strhtml += "</body>";
strhtml += "</html>";
mm.Body = strhtml;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Send(mm);
}
}
catch (Exception ex)
{
Response.Write("Error occurred: " + ex.Message);
}
}
Developer technologies | C#
Developer technologies | ASP.NET Core | Other
A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
1 answer
Sort by: Oldest
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
4 deleted comments
Comments have been turned off. Learn more