468,505 Members | 1,542 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

RequiredFieldValidator Dynamic Creation

Dear Friends,

I need your help. I am trying to dynamically create a
RequiredFieldValidator in the ItemCreated event of a DataList but cannot get
it to work. The errors seem to revolve around the .ControlToValidate
property.

When a new Item is created, I check the information coming in from my
database. Based on a field value (TypeID), I create a different control
needed for input: (TextBox, ListBox, DropdownList, etc...), add this control
to the current "row", and proceed. At that very moment, I'd like to create a
RequiredFieldValidator control and attach it to (.ControlToValidate) the
newly created control. This is where the problem occurs.

As I am using the DataList control, I cannot assign the .ID of my newly
created input control as it will give me a duplicate ID error, so I let the
DataList create the unique ID's. Therefore, I have tried to use this
..UniqueID with the .ControlToValidate property of the RequiredFieldValidator
control, but to no avail. ASP.NET generates an error saying that the
property is empty (""). So while all my input controls get added to the
datalist properly, I cannot seem to attach the RequiredFieldValidator to
those controls as the .ControlToValidate property is problematic in my case.

Any help is greatly appreciated.
Jan 24 '06 #1
1 5773
Try this

requiredFieldValidator.ControlToValidate = inputControl.ClientID

"Giovanni" wrote:
Dear Friends,

I need your help. I am trying to dynamically create a
RequiredFieldValidator in the ItemCreated event of a DataList but cannot get
it to work. The errors seem to revolve around the .ControlToValidate
property.

When a new Item is created, I check the information coming in from my
database. Based on a field value (TypeID), I create a different control
needed for input: (TextBox, ListBox, DropdownList, etc...), add this control
to the current "row", and proceed. At that very moment, I'd like to create a
RequiredFieldValidator control and attach it to (.ControlToValidate) the
newly created control. This is where the problem occurs.

As I am using the DataList control, I cannot assign the .ID of my newly
created input control as it will give me a duplicate ID error, so I let the
DataList create the unique ID's. Therefore, I have tried to use this
.UniqueID with the .ControlToValidate property of the RequiredFieldValidator
control, but to no avail. ASP.NET generates an error saying that the
property is empty (""). So while all my input controls get added to the
datalist properly, I cannot seem to attach the RequiredFieldValidator to
those controls as the .ControlToValidate property is problematic in my case.

Any help is greatly appreciated.

Jan 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Fernando Lopes | last post: by
2 posts views Thread by Hongbo | last post: by
1 post views Thread by Loui Mercieca | last post: by
reply views Thread by André Nobre | last post: by
1 post views Thread by Arpan | last post: by
3 posts views Thread by AG | last post: by
1 post views Thread by Preben Zacho | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.