Problem with RequiredFieldValidator in custom (C#) control

L

Lloyd Dupont

I have a composite control rougly like that::
====
class BlogComments : Control, INamingContainer, IPostBackEventHandler
{
Panel pAddComment;
TextBox tTitle;

protected override void CreateChildControls()
{
pAddComment = new Panel();
Controls.Add(pAddComment);

pAddComment.Controls.Add(tTitle = new TextBox());
tTitle.ID = "tTitle";

RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ErrorMessage = strings.Required;
rfv.ControlToValidate = "tTitle";
pAddComment.Controls.Add(rfv);
}
}
====
Now when I try to display a page (.aspx) where there is a BlogComment I get the following error:
===
[HttpException (0x80004005): Unable to find control id 'tTitle' referenced by the 'ControlToValidate' property of ''.]
System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String name, String propertyName) +221
System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid() +178
System.Web.UI.WebControls.BaseValidator.get_PropertiesValid() +36
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +46
===
Any tips?
 
L

Lloyd Dupont

forget it, bug in my code, I change the ID of tTitle agin one line below...

I have a composite control rougly like that::
====
class BlogComments : Control, INamingContainer, IPostBackEventHandler
{
Panel pAddComment;
TextBox tTitle;

protected override void CreateChildControls()
{
pAddComment = new Panel();
Controls.Add(pAddComment);

pAddComment.Controls.Add(tTitle = new TextBox());
tTitle.ID = "tTitle";

RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ErrorMessage = strings.Required;
rfv.ControlToValidate = "tTitle";
pAddComment.Controls.Add(rfv);
}
}
====
Now when I try to display a page (.aspx) where there is a BlogComment I get the following error:
===
[HttpException (0x80004005): Unable to find control id 'tTitle' referenced by the 'ControlToValidate' property of ''.]
System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String name, String propertyName) +221
System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid() +178
System.Web.UI.WebControls.BaseValidator.get_PropertiesValid() +36
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +46
===
Any tips?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top