473,761 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET CustomValidator on dynamic textboxes

Hello. I'm creating a form that has (up to) 10 identical panels on the
page, with each panel containing the same 8 textboxes for things like
school name, address, etc, and one dropdown box. The user chooses how
many schools they need to enter information for, and the form shows the
appropriate number of panels. All 10 panels are generated on page load,
then hidden until the user selects how many they need.

Now comes the tricky part. If the user selects "No" from the dropdown
box within a panel, the address for that panel needs to be required.
I've written a CustomValidator that refers to the Address textbox by ID
(eg. Address1). While the CustomValidator works, if I use this method I
will have to write separate CustomValidator s for each of the 10 panels.
Is there any way to write one validator that would work for all 10
Address textboxes? Here's the code I've got so far:

Sub reqAddress(send er as Object, args as ServerValidateE ventArgs)

Dim strAddress As String
Dim ddYesNo As String = CStr(args.Value )

strAddress = txtAddress1.Tex t // This is the line I want to make more
general

If ddYesNo = "No" And Len(strAddress) =0 Then
args.IsValid = False
Else
args.IsValid = True
End If

End Sub

Jun 26 '06 #1
1 3413
control array?

for x = 1 to 10
strAddress = txtAddresses[x].Text

pseudocode obviously :)
"theresa" wrote:
Hello. I'm creating a form that has (up to) 10 identical panels on the
page, with each panel containing the same 8 textboxes for things like
school name, address, etc, and one dropdown box. The user chooses how
many schools they need to enter information for, and the form shows the
appropriate number of panels. All 10 panels are generated on page load,
then hidden until the user selects how many they need.

Now comes the tricky part. If the user selects "No" from the dropdown
box within a panel, the address for that panel needs to be required.
I've written a CustomValidator that refers to the Address textbox by ID
(eg. Address1). While the CustomValidator works, if I use this method I
will have to write separate CustomValidator s for each of the 10 panels.
Is there any way to write one validator that would work for all 10
Address textboxes? Here's the code I've got so far:

Sub reqAddress(send er as Object, args as ServerValidateE ventArgs)

Dim strAddress As String
Dim ddYesNo As String = CStr(args.Value )

strAddress = txtAddress1.Tex t // This is the line I want to make more
general

If ddYesNo = "No" And Len(strAddress) =0 Then
args.IsValid = False
Else
args.IsValid = True
End If

End Sub

Jun 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1835
by: Dave | last post by:
I have added a custom validator to the EditItemTemplate of a DataGrid as follows: <EditItemTemplate> <asp:TextBox id=txtWorkDate CssClass="ResultsDim" runat="server" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.WorkDate","{0:g}") %>' > </asp:TextBox> <asp:requiredfieldvalidator id="RfvWorkDate" runat="server" ErrorMessage="Enter the Work Date" ControlToValidate="txtWorkDate"
1
330
by: Jim Heavey | last post by:
Hello, I was am wanting to validate that a user has made a selection from a dropdownlist control in a datagrid. Is my only option to use a "CustomValidator Control"? I am not quite sure how to write and attach JavaScript to the control to ensure the SelectedIndex > -1. Is there a way to do this in JavaScript (can you provide an example?) or should I just write Server side validation? Example:
3
1858
by: philipl | last post by:
hi, i have a textbox in my edititemtemplate in my datagrid. I have created a customvalidator for it, when i update the row the appropiate function gets called to customvalidate but the problem is that the error message in my customvalidator does not get printed in the datagrid even though I have set the isvalid property in the server function to false. Does anyone know why this is? Here is the code snippets:
1
1847
by: SMG | last post by:
Hi All. My forms has two textboxes, 1 username, 2 password. Both has requiredfield validator it works fine when there is no input in these textboxes. And the errorMsg is shown in ValidationSummary. Now I want to check the username should contain only chatacters, ( I want to use customvalidator), when i enter char+number it trap the event of customvalidator but it doesn't show the errormsg in the customValidator and submits the form.
5
4513
by: Markus Broy | last post by:
Hello everybody, I have a problem concerning the dynamic creation of a CustomValidator. If I create a CustomControl as shown in the code below and the page is post back the validation procedure is never called. In Page_Load Page Validate() is called and in the control which should be validated there is a non numeric value.
0
3537
by: ghafranabbas | last post by:
This is how you use the customvalidator control in any INamingContainer interface control (Datagrid, DataList, DataRepeater, etc). 1. In the ItemTemplate, place your customvalidator 2. Set the OnServerValidate property of the customvalidator 3. Get reference to the Data Item object (For DataList is DataListItem, for DataGrid its DataGridItem) 4. Get reference to any controls needed for validation 5. Perform the validation
0
1273
by: antonyliu2002 | last post by:
The full code is pasted below. It looks scarily long, but it's pretty simple. It is adapted from a sample code at MSDN. If you run it, and check it out from your browser, you'll see: CustomValidator ServerValidate Example Enter an even number: Zip:
3
1798
by: Jaime Stuardo | last post by:
Hi all... I'm trying to use a custom validator for a group of checkboxes in order to validate that at least 1 checkbox is checked before submitting the form. I placed 2 checkbox controls in the form and a CustomValidator. When I saw CustomValidator properties, the checkboxes aren't listed in ControlToValidate properties. Only textboxes are listed. Also, I set the ValidationGroup for the checkboxes to a name such as grpTipoEnvio and...
2
1963
by: Jeff | last post by:
hey net 3.5 I have problem with a customvalidator. I enter values into the TextBox named "txt" and clicks on the save button (ibSave) then the TestValidate method get triggered. TestValidate set args.IsValid = false and the customvalidator displays an error on the webpage. The problem is that when I check in the database, the value has still been added to the database. if the value entered in the TextBox is not a correct value, then...
0
9522
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
10111
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...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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
8770
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...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5215
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...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
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.