473,796 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RequiredFieldVa lidator Dynamic Creation

Dear Friends,

I need your help. I am trying to dynamically create a
RequiredFieldVa lidator in the ItemCreated event of a DataList but cannot get
it to work. The errors seem to revolve around the .ControlToValid ate
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
RequiredFieldVa lidator control and attach it to (.ControlToVali date) 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 .ControlToValid ate property of the RequiredFieldVa lidator
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 RequiredFieldVa lidator to
those controls as the .ControlToValid ate property is problematic in my case.

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

requiredFieldVa lidator.Control ToValidate = inputControl.Cl ientID

"Giovanni" wrote:
Dear Friends,

I need your help. I am trying to dynamically create a
RequiredFieldVa lidator in the ItemCreated event of a DataList but cannot get
it to work. The errors seem to revolve around the .ControlToValid ate
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
RequiredFieldVa lidator control and attach it to (.ControlToVali date) 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 .ControlToValid ate property of the RequiredFieldVa lidator
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 RequiredFieldVa lidator to
those controls as the .ControlToValid ate 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
5108
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 if I do not enter anything in the form in IE, then form won't be submitted but in other browsers it is submitted. I checked that JavaScript is enabled in Netscape, Opera, Mozilla, Firefox,
5
3240
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 ControlToValidate="AddressName" Display="Dynamic" ErrorMessage="First Name Is Required" Runat="server" CssClass="AlertText"
2
2101
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 fields as the following: ===== <form id="creditcardform" method="post" runat="server"> Email: <asp:textbox id="txtBillEmail" maxlength="50" width="200" runat="server" /> <asp:requiredfieldvalidator id="vp10" runat="server" initialvalue="" ...
1
1705
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 clientID property of the control return null. How do i assign the ControlToValidate if i cannot get the control ID. I am creating the RequiredFieldValidator in the prerender event. Thanks
0
1277
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 (this.ValidationRequired) { reqField = new RequiredFieldValidator(); reqField.ControlToValidate = this.ID; reqField.Text = "&nbsp;&nbsp;<img src=\"http://localhost/Extra/Images/Structure/exclamacao.gif\">";
1
2600
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 id="reqVal" ControlToValidate="txtVal" ErrorMessage="Please enter a value in the TextBox!" Display="Dynamic" runat="server"/> <asp:Button id="but1" Text="SUBMIT" runat="server"/> </form>
3
11722
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 work properly in a gridview, viewstate must be enabled. So, in order to minimize the size of viewstate for a page, I will sometimes turn off viewstate for each control in template columns. That means that the gridview must be databound on each...
2
6479
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) In Page_load, Dim Email As New Label
1
1351
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 accept the form. Why does this occure? Must be some setting I've missed, cause in other forms it works as it should, where the text is not displayed until the user click the accept button. My textbox and validator looks like this:
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.