G
Guest
I have a custom composite control which has a validator for a textbox. The validator and textbox are declared in the class and created in the CreateChildControls() method
Here is the code for the textbox, in CreateChildControls()
searchBox = new TextBox();
searchBox.ID = "searchBox";
searchBox.EnableViewState = false;
It is then added to a TableCell, which is added to a row, etc.
Here is the validator being created (also in CreateChildControls()):
searchBoxValidator = new RequiredFieldValidator();
searchBoxValidator.ID = "searchBoxValidator";
searchBoxValidator.EnableViewState = false;
searchBoxValidator.ControlToValidate = "searchBox";
searchBoxValidator.ErrorMessage = "You must enter a product ID";
This validator, again, is added to a TableCell, etc.
On a submit button's click event, I call searchBoxValidator.Validate(), which throws a NullReferenceException:
[NullReferenceException: Object reference not set to an instance of an object.]
AdminToolProduct.ProductSelectControl.searchButtonClick(Object sender, EventArgs e) in c:\inetpub\wwwroot\admintoolproduct_1\controls\productselectcontrol.cs:235
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
....
Any ideas? I've tried setting the ControlToValidate property of the validator to
UniqueID+"_searchBox", resulting in the same error. Besides, if the control to validate is not found, I thought an HttpException was thrown. I also noticed that for some reason, no client side validation is done, even though I explicity tried setting the EnableClientScript to true (doesn't seem to be anything showing up in the source). Am I setting up this validator in the wrong place, or doing something else wrong? Thank you for your time.
Here is the code for the textbox, in CreateChildControls()
searchBox = new TextBox();
searchBox.ID = "searchBox";
searchBox.EnableViewState = false;
It is then added to a TableCell, which is added to a row, etc.
Here is the validator being created (also in CreateChildControls()):
searchBoxValidator = new RequiredFieldValidator();
searchBoxValidator.ID = "searchBoxValidator";
searchBoxValidator.EnableViewState = false;
searchBoxValidator.ControlToValidate = "searchBox";
searchBoxValidator.ErrorMessage = "You must enter a product ID";
This validator, again, is added to a TableCell, etc.
On a submit button's click event, I call searchBoxValidator.Validate(), which throws a NullReferenceException:
[NullReferenceException: Object reference not set to an instance of an object.]
AdminToolProduct.ProductSelectControl.searchButtonClick(Object sender, EventArgs e) in c:\inetpub\wwwroot\admintoolproduct_1\controls\productselectcontrol.cs:235
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
....
Any ideas? I've tried setting the ControlToValidate property of the validator to
UniqueID+"_searchBox", resulting in the same error. Besides, if the control to validate is not found, I thought an HttpException was thrown. I also noticed that for some reason, no client side validation is done, even though I explicity tried setting the EnableClientScript to true (doesn't seem to be anything showing up in the source). Am I setting up this validator in the wrong place, or doing something else wrong? Thank you for your time.