471,092 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

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 5815
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.