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.Show Button when user is Logged In using C# and VB.Net in ASP.Net<p>I will get back soon.</p>https://www.aspforums.net:443/Threads/434785/Show-Button-when-user-is-Logged-In-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/434785/Show-Button-when-user-is-Logged-In-using-C-and-VBNet-in-ASPNet/Mon, 01 Jul 2019 00:11:27 GMTShow Button when user is Logged In using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="sha10oct"> sha10oct</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>Login.aspx</strong></p> <pre class="brush: html">Name : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtName&#34; /&gt; &lt;br /&gt; &lt;asp:Button Text=&#34;Login&#34; runat=&#34;server&#34; OnClick=&#34;LoginData&#34; /&gt;</pre> <p><strong>CS.aspx</strong></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;File Name&#34; /&gt; &lt;asp:TemplateField ItemStyle-HorizontalAlign=&#34;Center&#34; Visible=&#34;false&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID=&#34;lnkDownload&#34; runat=&#34;server&#34; Text=&#34;Download&#34; CommandArgument=&#39;&lt;%# Eval(&#34;Id&#34;) %&gt;&#39;&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField ItemStyle-HorizontalAlign=&#34;Center&#34; Visible=&#34;false&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID=&#34;lnkView&#34; runat=&#34;server&#34; Text=&#34;View&#34; CommandArgument=&#39;&lt;%# Eval(&#34;Id&#34;) %&gt;&#39;&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&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.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Configuration</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <p><strong>LoginCS.aspx.cs</strong></p> <pre class="brush: csharp">protected void LoginData(object sender, EventArgs e) { // Code for Login. Session[&#34;IsLogin&#34;] = true; Response.Redirect(&#34;CS.aspx&#34;); }</pre> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); bool IsLoggedIn = Session[&#34;IsLogin&#34;] != null ? Convert.ToBoolean(Session[&#34;IsLogin&#34;]) : false; if (IsLoggedIn) { GridView1.Columns[1].Visible = true; GridView1.Columns[2].Visible = true; } else { GridView1.Columns[1].Visible = false; GridView1.Columns[2].Visible = false; } } } private void BindGrid() { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = &#34;select Id, Name from tblFiles&#34;; cmd.Connection = con; con.Open(); GridView1.DataSource = cmd.ExecuteReader(); GridView1.DataBind(); con.Close(); } } }</pre> <p><strong>LoginVB.cs</strong></p> <pre class="brush: vb">Protected Sub LoginData(ByVal sender As Object, ByVal e As EventArgs) Session(&#34;IsLogin&#34;) = True Response.Redirect(&#34;CS.aspx&#34;) End Sub</pre> <p><strong>VB.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 IsPostBack Then BindGrid() Dim IsLoggedIn As Boolean = If(Session(&#34;IsLogin&#34;) IsNot Nothing, Convert.ToBoolean(Session(&#34;IsLogin&#34;)), False) If IsLoggedIn Then GridView1.Columns(1).Visible = True GridView1.Columns(2).Visible = True Else GridView1.Columns(1).Visible = False GridView1.Columns(2).Visible = False End If End If End Sub Private Sub BindGrid() Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand() cmd.CommandText = &#34;select Id, Name from tblFiles&#34; cmd.Connection = con con.Open() GridView1.DataSource = cmd.ExecuteReader() GridView1.DataBind() con.Close() End Using End Using End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/X2hYBul.gif" alt="" width="281" height="372" /></p>https://www.aspforums.net:443/Threads/434785/Show-Button-when-user-is-Logged-In-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/434785/Show-Button-when-user-is-Logged-In-using-C-and-VBNet-in-ASPNet/Mon, 01 Jul 2019 02:08:36 GMT