Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting Page.EnableEventValidation on Page_Init
    primarykey
    data
    text
    <p>I have a user control in which I have successfully set <code>Page.EnableEventValidation = false</code> in the <code>Page_Init</code> event in the codebehind (in order to render the page markup to a string):</p> <p><strong>MyControl.ascx.cs</strong></p> <pre><code>protected void Page_Init(object sender, EventArgs e) { if (Request.Form["__EVENTTARGET"] != null &amp;&amp; Request.Form["__EVENTTARGET"] == btnPrint.ClientID.Replace("_", "$")) { Page.EnableEventValidation = false; } } </code></pre> <p>However, when I attempt to duplicate this functionality on a separate page (this time in <code>runat=server</code> script tags)...</p> <p><strong>MyPage.aspx</strong></p> <pre><code>&lt;script runat="server"&gt; protected void Page_Init(object sender, EventArgs e) { if (Request.Form["__EVENTTARGET"] != null &amp;&amp; Request.Form["__EVENTTARGET"] == btnDownloadPDF.ClientID.Replace("_", "$")) { Page.EnableEventValidation = false; } } &lt;/script&gt; </code></pre> <p>... I get the following error:</p> <blockquote> <p>The 'EnableEventValidation' property can only be set in the page directive or in the configuration section.</p> </blockquote> <p>Now, in my first example, I was receiving this error when originally attempting to do this on <code>Page_Load</code>; however, it seems that you <em>can</em> disable event validation programmatically as long as it's done during (or before) <code>Page_Init</code>. Unfortunately the same does not work in my second example.</p> <p>Why does this work in one scenario and not the other? Is it related to the fact that the code is not in a codebehind?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload