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.Bootstrap form validation not working after page PostBack in ASP.Net<p>Check the code.</p> <p><strong><span style="text-decoration: underline;">MagterPage</span></strong></p> <pre class="brush: html">&lt;%@ Master Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;MasterPage.master.cs&#34; Inherits=&#34;MasterPage&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&gt; &lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css&#34; /&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css&#34; /&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/css/bootstrapValidator.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://code.jquery.com/jquery-1.10.2.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;script src=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js&#34;&gt;&lt;/script&gt; &lt;asp:ContentPlaceHolder ID=&#34;head&#34; runat=&#34;server&#34;&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/head&gt; &lt;body&gt; &lt;asp:ContentPlaceHolder ID=&#34;ContentPlaceHolder1&#34; runat=&#34;server&#34;&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;script type=&#34;text/javascript&#34;&gt; function openModal() { $(&#39;[id*=popModal]&#39;).modal({ backdrop: &#39;static&#39;, keyboard: false }); $(&#39;[id*=popModal]&#39;).on(&#34;hidden.bs.modal&#34;, function (e) { $(&#39;body&#39;).removeClass(&#39;modal-open&#39;); $(&#39;.modal-backdrop&#39;).remove(); }); } &lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; function btnNameSearch_Click(objTextBox, objBtnID) { if (window.event.keyCode == 13) { document.getElementById(objBtnID).focus(); document.getElementById(objBtnID).click(); } } &lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function () { ValidateFormField(); }); function ValidateFormField() { $(&#39;[id*=myForm]&#39;).bootstrapValidator({ container: &#39;#messages&#39;, feedbackIcons: { valid: &#39;glyphicon glyphicon-ok&#39;, invalid: &#39;glyphicon glyphicon-remove&#39;, validating: &#39;glyphicon glyphicon-refresh&#39; }, fields: { &#39;ctl00$ContentPlaceHolder1$txtResult&#39;: { validators: { notEmpty: { message: &#39;1st Textbox is required and cannot be empty&#39; } } }, &#39;ctl00$ContentPlaceHolder1$txtOutside&#39;: { validators: { notEmpty: { message: &#39;2nd Textbox is required and cannot be empty&#39; } } } } }); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong><span style="text-decoration: underline;">DefaultPage</span></strong></p> <pre class="brush: html">&lt;%@ Page Title=&#34;&#34; Language=&#34;C#&#34; MasterPageFile=&#34;~/MasterPage.master&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;Default.aspx.cs&#34; Inherits=&#34;_Default&#34; EnableEventValidation=&#34;false&#34; %&gt; &lt;asp:Content ID=&#34;Content1&#34; ContentPlaceHolderID=&#34;head&#34; runat=&#34;Server&#34;&gt; &lt;/asp:Content&gt; &lt;asp:Content ID=&#34;Content2&#34; ContentPlaceHolderID=&#34;ContentPlaceHolder1&#34; runat=&#34;Server&#34;&gt; &lt;form method=&#34;post&#34; action=&#34;&#34; id=&#34;myForm&#34; runat=&#34;server&#34;&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34;&gt; &lt;/asp:ScriptManager&gt; &lt;div class=&#34;container&#34;&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;a href=&#34;#&#34; data-target=&#34;#popModal&#34; data-toggle=&#34;modal&#34; class=&#34;btn btn-warning&#34;&gt;Search Records&lt;/a&gt;&lt;br /&gt; &lt;br /&gt; &lt;asp:UpdatePanel ID=&#34;UpdatePanel2&#34; runat=&#34;server&#34;&gt; &lt;ContentTemplate&gt; &lt;asp:TextBox ID=&#34;txtResult&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:TextBox ID=&#34;txtOutside&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:RadioButtonList ID=&#34;rblist&#34; runat=&#34;server&#34;&gt; &lt;asp:ListItem&gt;Oral B&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Colgate&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Crest&lt;/asp:ListItem&gt; &lt;/asp:RadioButtonList&gt; &lt;asp:UpdatePanel ID=&#34;UpdatePanel1&#34; runat=&#34;server&#34;&gt; &lt;ContentTemplate&gt; &lt;!-- Modal --&gt; &lt;asp:Label ID=&#34;Label1&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt;&lt;br /&gt; &lt;div class=&#34;modal fade&#34; id=&#34;popModal&#34; tabindex=&#34;-1&#34; role=&#34;dialog&#34; style=&#34;overflow: hidden&#34; aria-labelledby=&#34;popModalLabel&#34; aria-hidden=&#34;true&#34;&gt; &lt;div class=&#34;modal-dialog modal-lg&#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-label=&#34;Close&#34;&gt; &lt;span aria-hidden=&#34;true&#34;&gt;&amp;times;&lt;/span&gt;&lt;/button&gt; &lt;h4 class=&#34;modal-title&#34; id=&#34;popModalLabel&#34;&gt; Search Products&lt;/h4&gt; &lt;/div&gt; &lt;div class=&#34;modal-body&#34;&gt; &lt;form id=&#34;inputform&#34; action=&#34;#&#34; method=&#34;post&#34;&gt; &lt;div class=&#34;row&#34;&gt; &lt;div class=&#34;col-md-6&#34;&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;asp:TextBox ID=&#34;txtEID&#34; runat=&#34;server&#34; class=&#34;form-control&#34;&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;col-md-6&#34;&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;asp:TextBox ID=&#34;txtEName&#34; runat=&#34;server&#34; class=&#34;form-control&#34;&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;asp:Button ID=&#34;btnNameSearch&#34; CssClass=&#34;btn btn-primary&#34; Text=&#34;Search&#34; UseSubmitBehavior=&#34;false&#34; OnClick=&#34;btnNameSearch_Click&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt; &lt;div class=&#34;modal-footer&#34;&gt; &lt;div style=&#34;width: 35%; height: 200px&#34;&gt; &lt;asp:GridView ID=&#34;gvEmployee&#34; runat=&#34;server&#34; OnRowDataBound=&#34;gvEmployee_RowDataBound&#34; DataKeyNames=&#34;eid&#34; AutoGenerateColumns=&#34;false&#34; CssClass=&#34;table table-hover&#34; OnSelectedIndexChanged=&#34;gvEmployee_SelectedIndexChanged&#34; GridLines=&#34;None&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;eid&#34; HeaderText=&#34;EID&#34; /&gt; &lt;asp:BoundField DataField=&#34;ename&#34; HeaderText=&#34;EName&#34; /&gt; &lt;/Columns&gt; &lt;HeaderStyle BackColor=&#34;LightCoral&#34; ForeColor=&#34;White&#34;&gt;&lt;/HeaderStyle&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;div class=&#34;dl-horizontal&#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;/div&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;div class=&#34;col-md-9 col-md-offset-3&#34;&gt; &lt;div id=&#34;messages&#34;&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;div class=&#34;col-md-1 col-md-offset-3&#34;&gt; &lt;button type=&#34;submit&#34; class=&#34;btn btn-default&#34;&gt; Validate&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/asp:Content&gt; </pre> <p><strong><span style="text-decoration: underline;">Default.aspx.cs</span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { rblist.SelectedIndex = 2; this.txtEID.Attributes.Add(&#34;onkeypress&#34;, &#34;btnNameSearch_Click(this,&#39;&#34; + this.btnNameSearch.ClientID + &#34;&#39;)&#34;); } private void BindGrid() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn(&#34;eid&#34;, typeof(int)), new DataColumn(&#34;ename&#34;, typeof(string)), new DataColumn(&#34;Country&#34;,typeof(string)) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;); gvEmployee.DataSource = dt; gvEmployee.DataBind(); } protected void btnNameSearch_Click(object sender, EventArgs e) { //clsBusinessLayer objBAL = new clsBusinessLayer(); if (IsValid) { if (txtEID.Text == &#34;&#34; &amp;&amp; txtEName.Text == &#34;&#34;) { BindGrid(); ScriptManager.RegisterStartupScript(this, this.GetType(), &#34;Pop&#34;, &#34;$(function() { openModal(); });&#34;, true); } else if (txtEID.Text == &#34;&#34; &amp;&amp; txtEName.Text != &#34;&#34;) { //var dsEmployees = (DataSet)objBAL.LoadEmployees(txtEID.Text, txtEName.Text); //gvEmployee.DataSource = dsEmployees.Tables[0]; //gvEmployee.DataBind(); ScriptManager.RegisterStartupScript(this, this.GetType(), &#34;Pop&#34;, &#34;$(function() { openModal(); });&#34;, true); } else { //var dsEmployees = (DataSet)objBAL.LoadEmployees(txtEID.Text, txtEName.Text); BindGrid(); ScriptManager.RegisterStartupScript(this, this.GetType(), &#34;Pop&#34;, &#34;$(function() { openModal(); });&#34;, true); } } } protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes[&#34;onmouseover&#34;] = &#34;this.style.cursor=&#39;pointer&#39;;&#34;; //e.Row.Attributes[&#34;onmouseout&#34;] = &#34;this.style.textDecoration=&#39;none&#39;;&#34;; //e.Row.ToolTip = &#34;Click to Select row&#34;; e.Row.Attributes[&#34;onclick&#34;] = this.Page.ClientScript.GetPostBackClientHyperlink(this.gvEmployee, &#34;Select$&#34; + e.Row.RowIndex); } } protected void gvEmployee_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow grow = gvEmployee.SelectedRow; if (grow != null) { txtResult.Text = grow.Cells[1].Text; txtResult.Focus(); } }</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://imgur.com/iJmBCkm.gif" alt="" width="335" height="559" /></p>https://www.aspforums.net:443/Threads/124088/Bootstrap-form-validation-not-working-after-page-PostBack-in-ASPNet/https://www.aspforums.net:443/Threads/124088/Bootstrap-form-validation-not-working-after-page-PostBack-in-ASPNet/Thu, 06 Sep 2018 04:44:42 GMT