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 Hide ASP.Net Panel based on Button Clicked using C# and VB.Net<p>Hey <a class="username" rel="BubunDash"> BubunDash</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: html">&lt;asp:Button ID=&#34;Button1&#34; Text=&#34;UserLogin&#34; runat=&#34;server&#34; OnClick=&#34;UserLogin&#34; /&gt;&lt;br /&gt; &lt;br /&gt; &lt;asp:Button ID=&#34;Button2&#34; Text=&#34;AdminLogin&#34; runat=&#34;server&#34; OnClick=&#34;AdminLogin&#34; /&gt;&lt;br /&gt; &lt;asp:Panel runat=&#34;server&#34; ID=&#34;PanelUser&#34;&gt; &lt;asp:Label Text=&#34;UserName&#34; runat=&#34;server&#34; ID=&#34;lblUserName&#34; /&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;Text_UserName&#34; /&gt; &lt;asp:Label ID=&#34;lblUserPass&#34; Text=&#34;UserPassword&#34; runat=&#34;server&#34; /&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;Text_Password&#34; /&gt; &lt;/asp:Panel&gt; &lt;asp:Panel runat=&#34;server&#34; ID=&#34;PanelAdmin&#34;&gt; &lt;asp:Label ID=&#34;lblAdminName&#34; Text=&#34;AdminName&#34; runat=&#34;server&#34; /&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;Text_AdminUserName&#34; /&gt; &lt;asp:Label ID=&#34;lblAdminPassword&#34; Text=&#34;AdminPassword&#34; runat=&#34;server&#34; /&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;Text_AdminPassword&#34; /&gt; &lt;/asp:Panel&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</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { PanelUser.Visible = false; PanelAdmin.Visible = false; } } protected void UserLogin(object sender, EventArgs e) { string name = Text_UserName.Text; string password = Text_Password.Text; if (!string.IsNullOrEmpty(name) &amp;&amp; !string.IsNullOrEmpty(password)) { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT Name, Country FROM Customers WHERE Name =@Name AND Country = @Country&#34;, con)) { cmd.Parameters.AddWithValue(&#34;@Name&#34;, name); cmd.Parameters.AddWithValue(&#34;@Country&#34;, password); con.Open(); string value = Convert.ToString(cmd.ExecuteScalar()); if (!string.IsNullOrEmpty(value)) { //User Panel Response.Redirect(&#34;Default.aspx&#34;); } else { Text_UserName.Focus(); Text_UserName.BackColor = System.Drawing.Color.Yellow; } con.Close(); } } } else { PanelUser.Visible = true; } } protected void AdminLogin(object sender, EventArgs e) { string name = Text_AdminUserName.Text; string password = Text_AdminPassword.Text; if (!string.IsNullOrEmpty(name) &amp;&amp; !string.IsNullOrEmpty(password)) { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT Name, Country FROM Customers WHERE Name =@Name AND Country = @Country&#34;, con)) { cmd.Parameters.AddWithValue(&#34;@Name&#34;, name); cmd.Parameters.AddWithValue(&#34;@Country&#34;, password); con.Open(); string value = Convert.ToString(cmd.ExecuteScalar()); if (!string.IsNullOrEmpty(value)) { //Admin Panel Response.Redirect(&#34;Admin.aspx&#34;); } else { Text_AdminUserName.Focus(); Text_AdminUserName.BackColor = System.Drawing.Color.Yellow; } con.Close(); } } } else { PanelAdmin.Visible = true; } }</pre> <p><strong>VB.Net</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 PanelUser.Visible = False PanelAdmin.Visible = False End If End Sub Protected Sub UserLogin(ByVal sender As Object, ByVal e As EventArgs) Dim name As String = Text_UserName.Text Dim password As String = Text_Password.Text If Not String.IsNullOrEmpty(name) AndAlso Not String.IsNullOrEmpty(password) Then Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT Name, Country FROM Customers WHERE Name =@Name AND Country = @Country&#34;, con) cmd.Parameters.AddWithValue(&#34;@Name&#34;, name) cmd.Parameters.AddWithValue(&#34;@Country&#34;, password) con.Open() Dim value As String = Convert.ToString(cmd.ExecuteScalar()) If Not String.IsNullOrEmpty(value) Then Response.Redirect(&#34;Default.aspx&#34;) Else Text_UserName.Focus() Text_UserName.BackColor = System.Drawing.Color.Yellow End If con.Close() End Using End Using Else PanelUser.Visible = True End If End Sub Protected Sub AdminLogin(ByVal sender As Object, ByVal e As EventArgs) Dim name As String = Text_AdminUserName.Text Dim password As String = Text_AdminPassword.Text If Not String.IsNullOrEmpty(name) AndAlso Not String.IsNullOrEmpty(password) Then Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT Name, Country FROM Customers WHERE Name =@Name AND Country = @Country&#34;, con) cmd.Parameters.AddWithValue(&#34;@Name&#34;, name) cmd.Parameters.AddWithValue(&#34;@Country&#34;, password) con.Open() Dim value As String = Convert.ToString(cmd.ExecuteScalar()) If Not String.IsNullOrEmpty(value) Then Response.Redirect(&#34;Admin.aspx&#34;) Else Text_AdminUserName.Focus() Text_AdminUserName.BackColor = System.Drawing.Color.Yellow End If con.Close() End Using End Using Else PanelAdmin.Visible = True End If End Sub</pre> <p><strong>Screenshot</strong></p> <p><strong><img src="https://imgur.com/IzUBqR2.gif" alt="" width="469" height="170" /></strong></p>https://www.aspforums.net:443/Threads/459359/Show-Hide-ASPNet-Panel-based-on-Button-Clicked-using-C-and-VBNet/https://www.aspforums.net:443/Threads/459359/Show-Hide-ASPNet-Panel-based-on-Button-Clicked-using-C-and-VBNet/Fri, 04 Jan 2019 00:37:23 GMT