By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

RequiredFieldValidator Dynamic Creation

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.