ValidatorGenerator.GenerateValidators in custom DetailsView

Topics: Developer Forum, User Forum
Feb 5, 2007 at 9:44 AM
Hi There,

I have a custom control which derives from DetailsView, which is intended to function exactly as a normal details view but perform additional logic if it finds spefic attributes on the object it is data-bound to.

In the overriden void CreateChildControls() method I iterate through the controls, and call the AddValidation(controlId, propertyName) method for each TextBox:

protected override void CreateChildControls()
{
base.CreateChildControls();

ValidatorGenerator validatorGenerator = new ValidatorGenerator();

foreach (DetailsViewRow row in this.Rows)
{
if (row.Controls.Count > 1)
{
foreach (DataControlFieldCell cell in row.Cells)
{
foreach (Control c in cell.Controls)
{
if (c is TextBox)
{
validatorGenerator.AddValidation(c.ID, cell.ContainingField.HeaderText);
}
}
}
}
}

validatorGenerator.GenerateValidators(this.Page, handle);
}

I get an error on the last line: "The member 'Emailx0020Address' could not be found or does not contain any validation attributes."

The field that is databound does have a validation attribute:

RequiredStringValidator(ErrorMessage = "Email Address is required.")
DataObjectField(false, false, false)
public string Emailx0020Address
{
get
{
return Emailx0020_Address;
}
set
{
Emailx0020_Address = value;
}
}

Am i passing in the wrong values to the GenerateValidators method? handle is declared as:

static RuntimeTypeHandle handle = typeof(ListRecord).TypeHandle;

...within the custom details view control.

Thanks,

Dan
Coordinator
Feb 6, 2007 at 2:27 AM
Edited Apr 8, 2007 at 10:09 AM
From what I can tell that should work.
Does the Emailx0020Address property exists on the ListRecord class?
If so could you please contact me via my profile page.
http://www.codeplex.com/UserAccount/UserProfile.aspx?UserName=SimonCropp
Feb 6, 2007 at 9:38 AM
Hi Simon,

Yes - it did. Sample sent.

Many Thanks,

Dan
Coordinator
Feb 8, 2007 at 9:31 AM
This turned out to be a bug fixed in a recent checkin. The latest source can be downloaded from
http://www.codeplex.com/ValidationFramework/SourceControl/ListDownloadableCommits.aspx