How does Page.IsValid work?
<p>I have following code with a <code>RequiredFieldValidator</code>. The EnableClientScript property is set as "false" in the validation control. Also I have disabled script in browser.</p>

<p>I am NOT using Page.IsValid in code behind. Still, when I submit without any value in textbox I will get <code>error message</code>. </p>

<p>From comments of @Dai, I came to know that this can be an issue, if there is any code in <code>Page_Load</code> that is executed in a <code>postback</code>. There will be no validation errors thrown. </p>

<p>(However, for button click handler, there is no need to check Page.IsValid)</p>

<pre><code>        if (Page.IsPostBack)
        {
            string value = txtEmpName.Text;
            txtEmpName.Text = value + "Appended";
        }
</code></pre>

<p><strong>QUESTION</strong></p>

<ol>
<li>Why the server side validation does not happen before Page_Load?</li>
<li>Why it works fine when I use Page.IsValid?</li>
<li>Can you provide reference to an article that explains this? (Not something that says - always use <code>Page.IsValid</code>; but something that says what are the mandatory scenarios to use <code>Page.IsValid</code></li>
</ol>

<p><strong>UPDATE 1</strong></p>

<p>Refer <a href="http://blogs.microsoft.co.il/blogs/linqed/archive/2009/09/01/asp-net-validators-common-misconception.aspx" rel="nofollow">ASP.NET Validators Common Misconception</a></p>

<blockquote>
  <p>Page.IsValid is accessible only after running Page.Validate() method which is invoked implicitly somewhere after Page_Load. In case you keep all of your logic in a Page_Load event handler (which is highly discouraged!), call the Page.Validate() before checking the Page.IsValid.</p>
</blockquote>

<p><em>Note</em>: It is advised <em>not to keep</em> all the logic in Page_Load.. If something is to happen on button click event, move it to button click event handler. If something is to happen on dropdown event, move it to dropdown selected item change event handler</p>

<p><strong>UPDATE 2</strong></p>

<p>It seems like, we need to add <code>If(Page.IsValid)</code> in <code>button click</code> also if we are using a <code>Custom Validator</code> with server side validation. Refer <a href="http://stackoverflow.com/questions/11064613/customvalidator-not-working-well">CustomValidator not working well</a>.</p>

<p><strong>Note</strong>: Client side validation question is present here: <a href="http://stackoverflow.com/questions/13832818/whether-to-use-page-isvalid-or-page-clientvalidate-for-client-side-events">Whether to use Page_IsValid or Page_ClientValidate() (for Client Side Events)</a></p>

<p><strong>MARKUP</strong></p>

<pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript"&gt;
    alert('haiii');
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;form id="form1" runat="server"&gt;
&lt;div&gt;
    &lt;asp:ValidationSummary runat="server" ID="vsumAll" DisplayMode="BulletList" CssClass="validationsummary" ValidationGroup="ButtonClick" /&gt;
    &lt;asp:TextBox ID="txtEmpName" runat="server"&gt;&lt;/asp:TextBox&gt;
    &lt;asp:RequiredFieldValidator ID="valEmpName" runat="server" ControlToValidate="txtEmpName"
        EnableClientScript="false" ErrorMessage="RequiredFieldValidator" Text="*" Display="Dynamic"
        ValidationGroup="ButtonClick"&gt;&lt;/asp:RequiredFieldValidator&gt;
    &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" ValidationGroup="ButtonClick" /&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>CODE BEHIND</strong></p>

<pre><code>    protected void Button1_Click(object sender, EventArgs e)
    {
        string value = txtEmpName.Text;
        SubmitEmployee(value);
    }
</code></pre>

<p><strong>References</strong>:</p>

<ol>
<li><a href="http://stackoverflow.com/questions/1039465/should-i-always-call-page-isvalid">Should I always call Page.IsValid?</a></li>
<li><a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=121" rel="nofollow">ASP.NET Validation Controls – Important Points, Tips and Tricks</a></li>
<li><a href="http://stackoverflow.com/questions/11064613/customvalidator-not-working-well">CustomValidator not working well</a></li>
</ol>
