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.Form validation without form tag using jQuery in ASP.Net<p>Hi&nbsp;jovceka,</p> <p>You must use a form element.&nbsp;You can't use server side control without form tag.</p> <p>If you use you will get error&nbsp;Control 'txtUsername' of type 'TextBox' must be placed inside a form tag with runat=server.</p> <p>So If you don't want to use form tag then you need to use html controls and using jquery validate the controls.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&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;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://cdn.jsdelivr.net/json2/0.1/json2.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#34;[id*=btnSave]&#34;).bind(&#34;click&#34;, function () { if ($(&#34;[id*=txtUsername]&#34;).val() != &#34;&#34; &amp;&amp; $(&#34;[id*=txtPassword]&#34;).val() != &#34;&#34;) { $(&#34;[id*=lblUsername]&#34;).hide(); $(&#34;[id*=lblPassword]&#34;).hide(); var user = {}; user.Username = $(&#34;[id*=txtUsername]&#34;).val(); user.Password = $(&#34;[id*=txtPassword]&#34;).val(); $.ajax({ type: &#34;POST&#34;, url: &#34;Default.aspx/SaveUser&#34;, data: &#39;{user: &#39; + JSON.stringify(user) + &#39;}&#39;, contentType: &#34;application/json; charset=utf-8&#34;, dataType: &#34;json&#34;, success: function (response) { alert(&#34;User has been added successfully.&#34;); window.location.reload(); } }); return false; } else { if ($(&#34;[id*=txtUsername]&#34;).val() == &#34;&#34;) { $(&#34;[id*=lblUsername]&#34;).show(); } if ($(&#34;[id*=txtPassword]&#34;).val() == &#34;&#34;) { $(&#34;[id*=lblPassword]&#34;).show(); } } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Username:&lt;/td&gt; &lt;td&gt; &lt;input name=&#34;txtUsername&#34; type=&#34;text&#34; id=&#34;txtUsername&#34; /&gt; &lt;span id=&#34;lblUsername&#34; style=&#34;color: Red; display: none;&#34;&gt;Username required!&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password:&lt;/td&gt; &lt;td&gt; &lt;input name=&#34;txtPassword&#34; type=&#34;password&#34; id=&#34;txtPassword&#34; /&gt; &lt;span id=&#34;lblPassword&#34; style=&#34;color: Red; display: none;&#34;&gt;Password required!&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;submit&#34; name=&#34;btnSave&#34; value=&#34;Save&#34; id=&#34;btnSave&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/2NgDPb4.gif" alt="" width="236" height="126" /></span></strong></p>https://www.aspforums.net:443/Threads/695638/Form-validation-without-form-tag-using-jQuery-in-ASPNet/https://www.aspforums.net:443/Threads/695638/Form-validation-without-form-tag-using-jQuery-in-ASPNet/Mon, 29 Jul 2019 07:01:04 GMT