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.Validate page using JavaScript Page_ClientValidate function in ASP.Net<blockquote><cite>nedash says:</cite> <div class="line number1 index0 alt2"><code class="csharp plain">&lt;script type=</code><code class="csharp string">"text/javascript"</code><code class="csharp plain">&gt;</code></div> <div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">function Validate() {</code></div> <div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">var message = document.getElementById(</code><code class="csharp string">"message"</code><code class="csharp plain">);</code></div> <div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">var DPayam = document.getElementById(</code><code class="csharp string">"DPayam"</code><code class="csharp plain">);</code></div> <div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(Page_ClientValidate()) {</code></div> <div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">message.style.display = </code><code class="csharp string">"none"</code><code class="csharp plain">;</code></div> <div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">DPayam.style.display = </code><code class="csharp string">"block"</code><code class="csharp plain">;</code></div> <div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">else</code> <code class="csharp plain">{</code></div> <div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">DPayam.style.display = </code><code class="csharp string">"none"</code><code class="csharp plain">;</code></div> <div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">message.style.display = </code><code class="csharp string">"block"</code><code class="csharp plain">;</code></div> <div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;</code><code class="csharp plain">&lt;/script&gt;</code></div> </blockquote> <p>&nbsp;Change the above with the below code.</p> <pre class="brush: js">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;title&gt;&lt;/title&gt; &nbsp;&nbsp;&nbsp; &lt;style type=&#34;text/css&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .DPayam &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float: right; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; display: normal; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .atten &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float: right; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; direction: rtl; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; display: none; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: red; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size: 14.5px; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width: 350px; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin: 30px 0px 0 0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &lt;/style&gt; &nbsp;&nbsp;&nbsp; &lt;script type=&#34;text/javascript&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function Validate() { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var message = document.getElementById(&#34;message&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var DPayam = document.getElementById(&#34;DPayam&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Page_ClientValidate()) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.style.display = &#34;none&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DPayam.style.display = &#34;block&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DPayam.style.display = &#34;block&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.style.display = &#34;block&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &nbsp;&nbsp;&nbsp; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;Txtname&#34; CssClass=&#34;DPayam&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;asp:RequiredFieldValidator Display=&#34;Dynamic&#34; ID=&#34;RequiredFieldValidator1&#34; runat=&#34;server&#34; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ControlToValidate=&#34;Txtname&#34;&gt;&lt;/asp:RequiredFieldValidator&gt; &nbsp;&nbsp;&nbsp; &lt;div id=&#34;DPayam&#34; runat=&#34;server&#34; class=&#34;DPayam&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&#34;Label33&#34; runat=&#34;server&#34; CssClass=&#34;lblmalek&#34;&gt;plese click below button&lt;/asp:Label&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &nbsp;&nbsp;&nbsp; &lt;div id=&#34;message&#34; class=&#34;atten&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&#34;Label38&#34; runat=&#34;server&#34; CssClass=&#34;lblatten&#34;&gt;please enter name&lt;/asp:Label&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &nbsp;&nbsp;&nbsp; &lt;asp:Button CssClass=&#34;DPayam&#34; Text=&#34;Validate&#34; runat=&#34;server&#34; OnClientClick=&#34;Validate();&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><img src="http://i.imgur.com/DGrKeYO.gif" alt="" width="237" height="167" /></p>https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/Mon, 19 Jun 2017 07:10:20 GMTValidate page using JavaScript Page_ClientValidate function in ASP.Net<p>hi dharmendr</p> <p>again it doesn't do any thing see below code worked for div message:</p> <pre class="brush: csharp"> &lt;script type=&#34;text/javascript&#34;&gt; function WebForm_OnSubmit() { var message = document.getElementById(&#34;message&#34;); message.style.display = &#34;none&#34;; if (typeof (ValidatorOnSubmit) == &#34;function&#34; &amp;&amp; ValidatorOnSubmit() == false) { for (var i in Page_Validators) { try { if (!Page_Validators[i].isvalid) { message.style.display = &#34;block&#34;; } } catch (e) { } } return false; } return true; } &lt;/script&gt; </pre> <p>but below code doesn't work: </p> <pre class="brush: csharp">&lt;script type=&#34;text/javascript&#34;&gt; function Validate() { var message = document.getElementById(&#34;message&#34;); var DPayam = document.getElementById(&#34;DPayam&#34;); if (Page_ClientValidate()) { message.style.display = &#34;none&#34;; DPayam.style.display = &#34;block&#34;; } else { DPayam.style.display = &#34;block&#34;; message.style.display = &#34;block&#34;; } } &lt;/script&gt;</pre>https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/Mon, 19 Jun 2017 07:21:37 GMTValidate page using JavaScript Page_ClientValidate function in ASP.Net<p>Refer the below link.</p> <p><a href="http://www.aspforums.net/Threads/138234/how-to-use-javacode-for-displaying-div/Replies/1#Replies">http://www.aspforums.net/Threads/138234/how-to-use-javacode-for-displaying-div/Replies/1#Replies</a></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/Mon, 19 Jun 2017 07:34:56 GMTValidate page using JavaScript Page_ClientValidate function in ASP.Net<p>hi deharmendr</p> <p>your code is correct but here I want when click on validate button text="please click below button" &lt;div Dpayam"&gt; display=none and it doesn't show this text</p> <p>best regards</p> <p>neda</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/Mon, 19 Jun 2017 08:35:48 GMTValidate page using JavaScript Page_ClientValidate function in ASP.Net<p>Change the DPayam.style.display = "block"; to none in else condition.</p> <p>If it doesnt help you out then please provide screenshot of your requirement.</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/https://www.aspforums.net:443/Threads/138234/Validate-page-using-JavaScript-PageClientValidate-function-in-ASPNet/Mon, 19 Jun 2017 09:24:06 GMT