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.User Login Form in Bootstrap Modal Popup in ASP.Net<p>Reference: <a href="https://www.aspsnippets.com/Articles/Simple-User-Login-Form-example-in-ASPNet.aspx">Simple User Login Form example in ASP.Net</a></p> <p>Please note below HTML and Code are of Login page only. Rest coding remains same as the aobe referred article.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: xml">&lt;script type=&#34;text/javascript&#34; src=&#39;https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js&#39;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#39;https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js&#39;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; href=&#39;https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css&#39; media=&#34;screen&#34; /&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;input type = &#34;button&#34; id=&#34;btnShowLogin&#34; class=&#34;btn btn-primary&#34; value = &#34;Login&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#34;#btnShowLogin&#34;).click(function () { $(&#39;#LoginModal&#39;).modal(&#39;show&#39;); }); }); &lt;/script&gt; &lt;!-- Modal --&gt; &lt;div class=&#34;modal fade&#34; id=&#34;LoginModal&#34; tabindex=&#34;-1&#34; role=&#34;dialog&#34; aria-labelledby=&#34;ModalTitle&#34; aria-hidden=&#34;true&#34;&gt; &lt;div class=&#34;modal-dialog&#34;&gt; &lt;div class=&#34;modal-content&#34;&gt; &lt;div class=&#34;modal-header&#34;&gt; &lt;button type=&#34;button&#34; class=&#34;close&#34; data-dismiss=&#34;modal&#34; aria-hidden=&#34;true&#34;&gt; &amp;times;&lt;/button&gt; &lt;h4 class=&#34;modal-title&#34; id=&#34;ModalTitle&#34;&gt; Login&lt;/h4&gt; &lt;/div&gt; &lt;div class=&#34;modal-body&#34;&gt; &lt;label for=&#34;txtUsername&#34;&gt; Username&lt;/label&gt; &lt;asp:TextBox ID=&#34;txtUsername&#34; runat=&#34;server&#34; CssClass=&#34;form-control&#34; placeholder=&#34;Enter Username&#34; required /&gt; &lt;br /&gt; &lt;label for=&#34;txtPassword&#34;&gt; Password&lt;/label&gt; &lt;asp:TextBox ID=&#34;txtPassword&#34; runat=&#34;server&#34; TextMode=&#34;Password&#34; CssClass=&#34;form-control&#34; placeholder=&#34;Enter Username&#34; required /&gt; &lt;div class=&#34;checkbox&#34;&gt; &lt;asp:CheckBox ID=&#34;chkRememberMe&#34; Text=&#34;Remember Me&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt; &lt;div id=&#34;dvMessage&#34; runat=&#34;server&#34; visible=&#34;false&#34; class=&#34;alert alert-danger&#34;&gt; &lt;strong&gt;Error!&lt;/strong&gt; &lt;asp:Label ID=&#34;lblMessage&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;modal-footer&#34;&gt; &lt;asp:Button ID=&#34;btnLogin&#34; Text=&#34;Login&#34; runat=&#34;server&#34; OnClick=&#34;ValidateUser&#34; Class=&#34;btn btn-primary&#34; /&gt; &lt;button type=&#34;button&#34; class=&#34;btn btn-default&#34; data-dismiss=&#34;modal&#34;&gt; Close&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <pre class="brush: csharp">using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Web.Security; </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (this.Page.User.Identity.IsAuthenticated) { Response.Redirect(FormsAuthentication.DefaultUrl); } } protected void ValidateUser(object sender, EventArgs e) { string username = txtUsername.Text.Trim(); string password = txtPassword.Text.Trim(); int userId = 0; string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;Validate_User&#34;)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&#34;@Username&#34;, username); cmd.Parameters.AddWithValue(&#34;@Password&#34;, password); cmd.Connection = con; con.Open(); userId = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); } switch (userId) { case -1: dvMessage.Visible = true; lblMessage.Text = &#34;Username and/or password is incorrect.&#34;; ClientScript.RegisterStartupScript(this.GetType(), &#34;JS&#34;, &#34;$(function () { $(&#39;#LoginModal&#39;).modal(&#39;show&#39;); });&#34;, true); break; case -2: dvMessage.Visible = true; lblMessage.Text = &#34;Account has not been activated.&#34;; ClientScript.RegisterStartupScript(this.GetType(), &#34;JS&#34;, &#34;$(function () { $(&#39;#LoginModal&#39;).modal(&#39;show&#39;); });&#34;, true); break; default: if (!string.IsNullOrEmpty(Request.QueryString[&#34;ReturnUrl&#34;])) { FormsAuthentication.SetAuthCookie(username, chkRememberMe.Checked); Response.Redirect(Request.QueryString[&#34;ReturnUrl&#34;]); } else { FormsAuthentication.RedirectFromLoginPage(username, chkRememberMe.Checked); } break; } } }</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><span style="text-decoration: underline;"><strong><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=fb1b497b-3197-406a-b84e-aa3b22d92772.gif" alt="" width="486" height="369" /></strong></span></p>https://www.aspforums.net:443/Threads/882624/User-Login-Form-in-Bootstrap-Modal-Popup-in-ASPNet/https://www.aspforums.net:443/Threads/882624/User-Login-Form-in-Bootstrap-Modal-Popup-in-ASPNet/Mon, 25 Dec 2017 12:28:02 GMT