Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Validation object is not set to an instance
    primarykey
    data
    text
    <p>I'm new to validation and I have crated a simple webform that I am trying to validate, where I override the <code>EvaluateIsValid()</code> method from the <code>BaseValidator</code> class in the App_Code folder. In this method I am getting the error <strong>Object is not set to an instance of an object</strong> at the <code>this.GetControlValidationValue()</code> call to set the string.</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ValidApp.Default" %&gt; &lt;!DOCTYPE html&gt; &lt;script runat="server"&gt; protected void pageCvd_ServerValidate(object source, ServerValidateEventArgs args) { ValidApp.App_Code._Validators valid = new ValidApp.App_Code._Validators(usernameTxt.ClientID.ToString()); } &lt;/script&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div style="display:inline-block; width:200px;"&gt; &lt;asp:CustomValidator ID="pageValidatorCvd" runat="server" EnableClientScript="false" OnServerValidate="pageCvd_ServerValidate"&gt;&lt;/asp:CustomValidator&gt; &lt;asp:Label ID="usernameLbl" runat="server" Text="Username:" style="width:50px; font-size:xx-small"&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="usernameTxt" runat="server" style="width:100px; font-size:xx-small"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:Label ID="passwordLbl" runat="server" Text="Password:" style="width:50px; font-size:xx-small"&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="passwordTxt" runat="server" style="width:100px; font-size:xx-small"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Button ID="registryBtn" runat="server" OnCommand="registryBtn_Command" CommandName="" CommandArgument="" Text="Register" style="width:50px; font-size:xx-small"/&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <hr> <p><strong>Code Behind</strong></p> <hr> <pre><code>namespace ValidApp.App_Code { public class _Validators : BaseValidator { private string regex; private string errorMessage; private string controlToValidate; protected override bool EvaluateIsValid() { string value = this.GetControlValidationValue(controlToValidate); return Regex.IsMatch(value, regex); } public _Validators(string controlToValidate = "", string regex = @"^[a-z0-9]{6-8}$", string errorMessage = "The Username is not valid!") { this.regex = regex; this.errorMessage = errorMessage; this.controlToValidate = controlToValidate; bool validation = EvaluateIsValid(); } } } </code></pre> <p>I have tried to create my own custom validation on <code>&lt;%@ Register &gt;</code> but to no avail.</p> <p>Any ideas where I am going wrong?</p>
    singulars
    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