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.Hide Button after second Login using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="KatieNgoc"> KatieNgoc</a>,</p> <p>Create a field in table as count which will keep tracking of updated count of user login. Refer below code.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>CS.aspx</strong></p> <pre class="brush: html">Name : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtName&#34; /&gt; &lt;asp:Button Text=&#34;Login&#34; runat=&#34;server&#34; OnClick=&#34;Login&#34; /&gt;</pre> <p><strong>Default.aspx</strong></p> <pre class="brush: html">&lt;asp:Label ID=&#34;lblName&#34; runat=&#34;server&#34; /&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtData&#34; /&gt; &lt;asp:Button Text=&#34;Print&#34; runat=&#34;server&#34; ID=&#34;btnPrint&#34; /&gt;&lt;br /&gt; &lt;asp:LinkButton ID=&#34;LinkButton1&#34; Text=&#34;Logout&#34; runat=&#34;server&#34; PostBackUrl=&#34;~/CS.aspx&#34; /&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.Configuration; using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data Imports System.Configuration Imports System.Data.SqlClient</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Login(object sender, EventArgs e) { Session[&#34;Name&#34;] = txtName.Text; Response.Redirect(&#34;Default.aspx&#34;); }</pre> <p><strong>Default.aspx.cs</strong></p> <pre class="brush: vb">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { int count = 1; string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;SELECT tblData WHERE Name = @Name&#34;); cmd.Parameters.AddWithValue(&#34;@Name&#34;, Session[&#34;Name&#34;].ToString()); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count &gt; 0) { cmd = new SqlCommand(&#34;UPDATE tblData SET Count = @Count WHERE Name = @Name&#34;); cmd.Parameters.AddWithValue(&#34;@Count&#34;, count + 1); cmd.Parameters.AddWithValue(&#34;@Name&#34;, Session[&#34;Name&#34;].ToString()); con.Open(); cmd.ExecuteNonQuery(); cmd = new SqlCommand(&#34;SELECT Count FROM tblData WHERE Name = @Name&#34;); cmd.Parameters.AddWithValue(&#34;@Count&#34;, Session[&#34;Name&#34;].ToString()); int updatedCount = Convert.ToInt16(cmd.ExecuteScalar()); con.Close(); if (updatedCount &gt; 2) { txtData.Visible = false; btnPrint.Visible = false; } } lblName.Text = Session[&#34;Name&#34;].ToString(); } }</pre> <p><strong>CS.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Login(ByVal sender As Object, ByVal e As EventArgs) Session(&#34;Name&#34;) = txtName.Text Response.Redirect(&#34;Default.aspx&#34;) End Sub</pre> <p><strong>Default.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim count As Integer = 1 Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim con As SqlConnection = New SqlConnection(constr) Dim cmd As SqlCommand = New SqlCommand(&#34;SELECT tblData WHERE Name = @Name&#34;) cmd.Parameters.AddWithValue(&#34;@Name&#34;, Session(&#34;Name&#34;).ToString()) Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() da.Fill(dt) If dt.Rows.Count &gt; 0 Then cmd = New SqlCommand(&#34;UPDATE tblData SET Count = @Count WHERE Name = @Name&#34;) cmd.Parameters.AddWithValue(&#34;@Count&#34;, count + 1) cmd.Parameters.AddWithValue(&#34;@Name&#34;, Session(&#34;Name&#34;).ToString()) con.Open() cmd.ExecuteNonQuery() cmd = New SqlCommand(&#34;SELECT Count FROM tblData WHERE Name = @Name&#34;) cmd.Parameters.AddWithValue(&#34;@Count&#34;, Session(&#34;Name&#34;).ToString()) Dim updatedCount As Integer = Convert.ToInt16(cmd.ExecuteScalar()) con.Close() If updatedCount &gt; 2 Then txtData.Visible = False btnPrint.Visible = False End If End If lblName.Text = Session(&#34;Name&#34;).ToString() End If End Sub</pre>https://www.aspforums.net:443/Threads/179974/Hide-Button-after-second-Login-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/179974/Hide-Button-after-second-Login-using-C-and-VBNet-in-ASPNet/Tue, 06 Aug 2019 07:51:02 GMT