Note that there are some explanatory texts on larger screens.

plurals
  1. POException without YSOD
    text
    copied!<p>So I set up my Global.asax file to email me when an unhanded exception occurred. I get an email with exceptions that don't appear to the user, and the code appears to be working just fine at the client end and the page loads and does what is expected.</p> <p>I have this code in the aspx file, which shows a checkbox based on a role or a customer number started with specific characters...</p> <pre><code>&lt;% if (Roles.IsUserInRole("Admin") || txtAccountNo.Text.Substring(0, 2) == "UK" || txtAccountNo.Text.Substring(0, 2) == "FR" || txtAccountNo.Text.Substring(0, 2) == "IT" || txtAccountNo.Text.Substring(0, 2) == "DK" || txtAccountNo.Text.Substring(0, 2) == "SE") { %&gt; &lt;label for="chkExpressDelivery"&gt;&lt;asp:Literal ID="Literal14" runat="server" Text="&lt;%$ Resources:LocalizedText, fieldLabel_ExpressDelivery %&gt;"&gt;&lt;/asp:Literal&gt;&lt;span class="small"&gt;&lt;/span&gt;&lt;/label&gt; &lt;asp:CheckBox ID="chkExpressDelivery" runat="server" Width="50px" CssClass="_checkbox _normalcheckbox" Text="&amp;nbsp;" /&gt; &lt;%} %&gt; </code></pre> <p>now txtAccountNo is populated from a user profile property in the Page_Load event in the aspx.cs file.</p> <p>the error message i receive in the email (which the client never sees) is </p> <blockquote> <p>Index and length must refer to a location within the string. Parameter name: length</p> </blockquote> <p>I understand the error message - that it's saying the txtAccountNo.Text is basically empty when that code runs, but what i dont understand is, the client never sees this error and the page behaves as i want it to.</p> <p>BUT, if i turn on custom error messages in the web.config file, the client is directed to the custom error page, but without it, no error as far as the client is concerned. </p> <p>So how can i correct this error so i can turn on my custom error pages?</p> <p>I hope this makes sense! Let me know if you need any more info.</p> <p>Thanks</p> <p>Stuart</p> <p>this code now works...</p> <pre><code>&lt;% if (txtAccountNo.Text.Length &gt; 0 &amp;&amp; (Roles.IsUserInRole("Admin") || txtAccountNo.Text.Substring(0, 2) == "UK" || txtAccountNo.Text.Substring(0, 2) == "FR" || txtAccountNo.Text.Substring(0, 2) == "IT" || txtAccountNo.Text.Substring(0, 2) == "DK" || txtAccountNo.Text.Substring(0, 2) == "SE")) { %&gt; &lt;label for="chkExpressDelivery"&gt;&lt;asp:Literal ID="Literal14" runat="server" Text="&lt;%$ Resources:LocalizedText, fieldLabel_ExpressDelivery %&gt;"&gt;&lt;/asp:Literal&gt;&lt;span class="small"&gt;&lt;/span&gt;&lt;/label&gt; &lt;asp:CheckBox ID="chkExpressDelivery" runat="server" Width="50px" CssClass="_checkbox _normalcheckbox" Text="&amp;nbsp;" /&gt; &lt;%} %&gt; </code></pre>
 

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