G
Guest
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.
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.