473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 5969
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe | last post by:
Hello, I have created a login page using dotnet. I am using requiredFieldValidator and noticed that the code works fine in IE but not in Netscape, Opera, Mozilla, Firefox, etc. For example...
5
by: Fernando Lopes | last post by:
Hi. I want to show an image in a requiredfield validator instead of "*". So, I 'm set the requiredfieldvalidator attributes like following: <asp:RequiredFieldValidator id=rfvFirstName...
2
by: Hongbo | last post by:
Hi, I have a Asp.Net written in C#. It serve as information input form. The form encounters sort of random problem with the email field and state field. I have validator attached with these 2...
1
by: Loui Mercieca | last post by:
HI, I need to dynamically create a RequiredFieldValidator for a control. I am havind problems when assigning the ControlToValidate property of the RequiredFieldValidator. The uniqueId and...
0
by: André Nobre | last post by:
Hi all, I´m having a little trouble with a requiredfieldvalitor in a custom control. I put a validator in runtime, as this code: protected override void OnInit(EventArgs e) { if...
1
by: Arpan | last post by:
Suppose I have the following RequiredFieldValidator control which validates a TextBox: <form id="form1" runat="server"> <asp:TextBox id="txtVal" runat="server"/> <asp:RequiredFieldValidator...
3
by: AG | last post by:
Below is code (slightly modified and converted to VB) that was provided to me in response to another post. I am using it to demonstrate another problem. In order for paging and other features to...
2
by: Christina | last post by:
Hello !! I am creating a dynamic textbox and want to validate it using the requiredfieldvalidator. These are the steps which I tried: ==================================================== 1)...
1
by: Preben Zacho | last post by:
Hi there I have a RequiredFieldValidator that displays the text "Required field" for a textbox. The problem is, that the text "Required field" is displayed BEFORE the user presses the button to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.