ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Send confirmation Email after Approve request using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="nid@patel"> nid@patel</a>,</p> <p>Refer below sample code.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;div class=&#34;container-fluid&#34;&gt; &lt;div class=&#34;col-sm-3&#34;&gt; &lt;%--menu panel--%&gt; &lt;asp:Panel ID=&#34;pnl_menu&#34; runat=&#34;server&#34; CssClass=&#34;panel-default&#34;&gt; &lt;div class=&#34;panel-heading&#34; style=&#34;background-color: lightcoral&#34;&gt; &lt;h4 class=&#34;text-center&#34;&gt; &lt;strong&gt;Menu&lt;/strong&gt;&lt;/h4&gt; &lt;/div&gt; &lt;div class=&#34;panel-body&#34; style=&#34;background-color: cornflowerblue&#34;&gt; &lt;div class=&#34;col-sm-8&#34;&gt; &lt;asp:Button ID=&#34;btn_Au&#34; CssClass=&#34;btn btn-block btn-primary&#34; runat=&#34;server&#34; Text=&#34;Approve Users&#34; /&gt; &lt;asp:Button ID=&#34;btn_Alu&#34; CssClass=&#34;btn btn-block btn-primary&#34; runat=&#34;server&#34; Text=&#34;All User&#34; /&gt; &lt;asp:Button ID=&#34;btn_state&#34; CssClass=&#34;btn btn-block btn-primary&#34; runat=&#34;server&#34; Text=&#34;Manage States&#34; OnClick=&#34;btn_state_Click&#34; /&gt; &lt;asp:Button ID=&#34;btn_dist&#34; CssClass=&#34;btn btn-block btn-primary&#34; runat=&#34;server&#34; Text=&#34;Manage Districts&#34; OnClick=&#34;btn_dist_Click&#34; /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/asp:Panel&gt; &lt;/div&gt; &lt;div class=&#34;col-sm-9&#34;&gt; &lt;asp:Panel ID=&#34;Panel_cntnt&#34; CssClass=&#34;panel-default&#34; runat=&#34;server&#34;&gt; &lt;div class=&#34;panel-heading&#34; style=&#34;background-color: lightcoral&#34;&gt; &lt;h4&gt; &lt;strong&gt;Content&lt;/strong&gt;&lt;/h4&gt; &lt;/div&gt; &lt;div class=&#34;panel-body&#34;&gt; &lt;asp:Panel ID=&#34;pnl_aut&#34; runat=&#34;server&#34;&gt; &lt;div class=&#34;panel-heading&#34;&gt; &lt;h1 class=&#34;text-center&#34;&gt; Approve Users&lt;/h1&gt; &lt;asp:Label ID=&#34;lbl_app&#34; runat=&#34;server&#34;&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class=&#34;panel-body&#34;&gt; &lt;asp:GridView CssClass=&#34;table table-bordered table-striped table-hover&#34; ID=&#34;Gv_approve&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;False&#34; CellPadding=&#34;6&#34; DataSourceID=&#34;SqlDataSource1&#34; ForeColor=&#34;#333333&#34; GridLines=&#34;None&#34; Width=&#34;489px&#34; DataKeyNames=&#34;Id&#34;&gt; &lt;AlternatingRowStyle BackColor=&#34;White&#34; ForeColor=&#34;#284775&#34; /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Id&#34; SortExpression=&#34;Id&#34; InsertVisible=&#34;False&#34; ReadOnly=&#34;True&#34; /&gt; &lt;asp:BoundField DataField=&#34;email&#34; HeaderText=&#34;Email&#34; SortExpression=&#34;email&#34; /&gt; &lt;asp:BoundField DataField=&#34;status&#34; HeaderText=&#34;Status&#34; SortExpression=&#34;status&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;Approve&#34;&gt; &lt;HeaderTemplate&gt; &lt;div class=&#34;text-center&#34;&gt; &lt;asp:CheckBox ID=&#34;CheckBox2&#34; runat=&#34;server&#34; AutoPostBack=&#34;True&#34; OnCheckedChanged=&#34;CheckBox2_CheckedChanged&#34; /&gt; Approve/Reject &lt;/div&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID=&#34;CheckBox1&#34; runat=&#34;server&#34; /&gt; &lt;/ItemTemplate&gt; &lt;ItemStyle HorizontalAlign=&#34;Center&#34; /&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;EditRowStyle BackColor=&#34;#999999&#34; /&gt; &lt;FooterStyle BackColor=&#34;#5D7B9D&#34; Font-Bold=&#34;True&#34; ForeColor=&#34;White&#34; /&gt; &lt;HeaderStyle BackColor=&#34;#5D7B9D&#34; Font-Bold=&#34;True&#34; ForeColor=&#34;White&#34; /&gt; &lt;PagerStyle BackColor=&#34;#284775&#34; ForeColor=&#34;White&#34; HorizontalAlign=&#34;Center&#34; /&gt; &lt;RowStyle BackColor=&#34;#F7F6F3&#34; ForeColor=&#34;#333333&#34; /&gt; &lt;SelectedRowStyle BackColor=&#34;#E2DED6&#34; Font-Bold=&#34;True&#34; ForeColor=&#34;#333333&#34; /&gt; &lt;SortedAscendingCellStyle BackColor=&#34;#E9E7E2&#34; /&gt; &lt;SortedAscendingHeaderStyle BackColor=&#34;#506C8C&#34; /&gt; &lt;SortedDescendingCellStyle BackColor=&#34;#FFFDF8&#34; /&gt; &lt;SortedDescendingHeaderStyle BackColor=&#34;#6F8DAE&#34; /&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID=&#34;SqlDataSource1&#34; runat=&#34;server&#34; ConnectionString=&#34;&lt;%$ ConnectionStrings:Mycon %&gt;&#34; SelectCommand=&#34;SELECT [Id], [email], [status] FROM [registration] WHERE ([status] = 0)&#34;&gt; &lt;SelectParameters&gt; &lt;asp:Parameter DefaultValue=&#34;0&#34; Name=&#34;status&#34; Type=&#34;String&#34; /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;/div&gt; &lt;asp:Button ID=&#34;btn_approve&#34; CssClass=&#34;btn btn-default&#34; runat=&#34;server&#34; Text=&#34;Approve&#34; OnClick=&#34;btn_approve_Click&#34; /&gt; &lt;asp:Button ID=&#34;btn_rjct&#34; CssClass=&#34;btn btn-default&#34; runat=&#34;server&#34; Text=&#34;Reject&#34; OnClick=&#34;btn_rjct_Click&#34; /&gt; &lt;/asp:Panel&gt; &lt;/div&gt; &lt;/asp:Panel&gt; &lt;/div&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Net.Mail; using System.Net; </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data Imports System.Data.SqlClient Imports System.Net Imports System.Net.Mail </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void CheckBox2_CheckedChanged(object sender, EventArgs e) { CheckBox check = sender as CheckBox; if (check.Checked) { foreach (GridViewRow row in Gv_approve.Rows) { CheckBox status = (row.Cells[3].FindControl(&#34;CheckBox1&#34;) as CheckBox); status.Checked = true; } } else { foreach (GridViewRow row in Gv_approve.Rows) { CheckBox status = (row.Cells[3].FindControl(&#34;CheckBox1&#34;) as CheckBox); status.Checked = false; } } } protected void btn_approve_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;Mycon&#34;].ToString()); foreach (GridViewRow row in Gv_approve.Rows) { CheckBox status = (row.Cells[3].FindControl(&#34;CheckBox1&#34;) as CheckBox); if (status.Checked) { try { SqlCommand cmd = new SqlCommand(&#34;Update registration set status=1 where email= + &#39;&#34; + row.Cells[1].Text + &#34;&#39;&#34;, con); cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); int suc = cmd.ExecuteNonQuery(); SqlDataReader dar = cmd.ExecuteReader(); if (suc &gt; 0) { SendMail(row.Cells[1].Text); Gv_approve.DataBind(); if (Gv_approve.Rows.Count == 0) { lbl_app.CssClass = &#34;text-center text-primary&#34;; lbl_app.Text = &#34;All Users are approved &#34;; btn_approve.Visible = false; } } } catch { } finally { if (con.State == ConnectionState.Open) con.Close(); } } } lbl_app.CssClass = &#34;text-center text-success&#34;; Response.Redirect(&#34;MIS_admin.aspx&#34;); lbl_app.Text = &#34;Status Updated Successfully&#34;; } private void SendMail(string recipient) { MailMessage mm = new MailMessage(&#34;sender@gmail.com&#34;, recipient); mm.Subject = &#34;Approval&#34;; mm.Body = &#34;You are now active&#34;; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = &#34;smtp.gmail.com&#34;; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(); NetworkCred.UserName = &#34;sender@gmail.com&#34;; NetworkCred.Password = &#34;&lt;password&gt;&#34;; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } protected void btn_rjct_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;Mycon&#34;].ToString()); foreach (GridViewRow row in Gv_approve.Rows) { CheckBox status = (row.Cells[3].FindControl(&#34;CheckBox1&#34;) as CheckBox); if (status.Checked) { try { SqlCommand cmd = new SqlCommand(&#34;delete from registration where email= + &#39;&#34; + row.Cells[1].Text + &#34;&#39;&#34;, con); cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); int suc = cmd.ExecuteNonQuery(); if (suc &gt; 0) { SendMail(row.Cells[1].Text); Gv_approve.DataBind(); if (Gv_approve.Rows.Count == 0) { lbl_app.CssClass = &#34;text-center text-primary&#34;; lbl_app.Text = &#34;All Users are rejected &#34;; btn_approve.Visible = false; } } } catch { } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } } lbl_app.CssClass = &#34;text-center text-success&#34;; lbl_app.Text = &#34;Status Updated Successfully&#34;; } protected void btn_state_Click(object sender, EventArgs e) { Response.Redirect(&#34;MIS_Manage_States.aspx&#34;); } protected void btn_dist_Click(object sender, EventArgs e) { Response.Redirect(&#34;MIS_Manage_District.aspx&#34;); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Dim check As CheckBox = TryCast(sender, CheckBox) If check.Checked Then For Each row As GridViewRow In Gv_approve.Rows Dim status As CheckBox = (TryCast(row.Cells(3).FindControl(&#34;CheckBox1&#34;), CheckBox)) status.Checked = True Next Else For Each row As GridViewRow In Gv_approve.Rows Dim status As CheckBox = (TryCast(row.Cells(3).FindControl(&#34;CheckBox1&#34;), CheckBox)) status.Checked = False Next End If End Sub Protected Sub btn_approve_Click(ByVal sender As Object, ByVal e As EventArgs) Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;Mycon&#34;).ToString()) For Each row As GridViewRow In Gv_approve.Rows Dim status As CheckBox = (TryCast(row.Cells(3).FindControl(&#34;CheckBox1&#34;), CheckBox)) If status.Checked Then Try Dim cmd As SqlCommand = New SqlCommand(&#34;Update registration set status=1 where email= + &#39;&#34; &amp; row.Cells(1).Text &amp; &#34;&#39;&#34;, con) cmd.CommandType = CommandType.Text cmd.Connection = con con.Open() Dim suc As Integer = cmd.ExecuteNonQuery() Dim dar As SqlDataReader = cmd.ExecuteReader() If suc &gt; 0 Then SendMail(row.Cells(1).Text) Gv_approve.DataBind() If Gv_approve.Rows.Count = 0 Then lbl_app.CssClass = &#34;text-center text-primary&#34; lbl_app.Text = &#34;All Users are approved &#34; btn_approve.Visible = False End If End If Catch Finally If con.State = ConnectionState.Open Then con.Close() End Try End If Next lbl_app.CssClass = &#34;text-center text-success&#34; Response.Redirect(&#34;MIS_admin.aspx&#34;) lbl_app.Text = &#34;Status Updated Successfully&#34; End Sub Private Sub SendMail(ByVal recipient As String) Dim mm As MailMessage = New MailMessage(&#34;sender@gmail.com&#34;, recipient) mm.Subject = &#34;Approval&#34; mm.Body = &#34;You are now active&#34; mm.IsBodyHtml = True Dim smtp As SmtpClient = New SmtpClient() smtp.Host = &#34;smtp.gmail.com&#34; smtp.EnableSsl = True Dim NetworkCred As NetworkCredential = New NetworkCredential() NetworkCred.UserName = &#34;sender@gmail.com&#34; NetworkCred.Password = &#34;&lt;password&gt;&#34; smtp.UseDefaultCredentials = True smtp.Credentials = NetworkCred smtp.Port = 587 smtp.Send(mm) End Sub Protected Sub btn_rjct_Click(ByVal sender As Object, ByVal e As EventArgs) Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;Mycon&#34;).ToString()) For Each row As GridViewRow In Gv_approve.Rows Dim status As CheckBox = (TryCast(row.Cells(3).FindControl(&#34;CheckBox1&#34;), CheckBox)) If status.Checked Then Try Dim cmd As SqlCommand = New SqlCommand(&#34;delete from registration where email= + &#39;&#34; &amp; row.Cells(1).Text &amp; &#34;&#39;&#34;, con) cmd.CommandType = CommandType.Text cmd.Connection = con con.Open() Dim suc As Integer = cmd.ExecuteNonQuery() If suc &gt; 0 Then SendMail(row.Cells(1).Text) Gv_approve.DataBind() If Gv_approve.Rows.Count = 0 Then lbl_app.CssClass = &#34;text-center text-primary&#34; lbl_app.Text = &#34;All Users are rejected &#34; btn_approve.Visible = False End If End If Catch Finally If con.State = ConnectionState.Open Then con.Close() End If End Try End If Next lbl_app.CssClass = &#34;text-center text-success&#34; lbl_app.Text = &#34;Status Updated Successfully&#34; End Sub Protected Sub btn_state_Click(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect(&#34;MIS_Manage_States.aspx&#34;) End Sub Protected Sub btn_dist_Click(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect(&#34;MIS_Manage_District.aspx&#34;) End Sub</pre>https://www.aspforums.net:443/Threads/719063/Send-confirmation-Email-after-Approve-request-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/719063/Send-confirmation-Email-after-Approve-request-using-C-and-VBNet-in-ASPNet/Wed, 14 Aug 2019 03:59:56 GMT