473,386 Members | 1,817 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,386 software developers and data experts.

dynamic validators

Is there a way to, based on the selection of another control, add a required
field validator to another field (code behind vb.net)?
I don't want the field to be required unless a checkbox or date field has
been entered.

Thanx.
Nov 19 '05 #1
3 1066
Sure, in Page_Load:

if (ConditionsMet)
{
RequiredFieldValidator val = new RequiredFieldValidator();
val.ControlToValidate = "idOfOtherControl";
val.Text = "* Required";
val.ErrorMessage = "You must provide a value for my other control";
somePlaceHolderInYourPage.Controls.Add(val);
}

So this assumes you have some <asp:PlaceHolder> or other control positioned
in the page where you want to add in your validation control.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Is there a way to, based on the selection of another control, add a
required field validator to another field (code behind vb.net)? I
don't want the field to be required unless a checkbox or date field
has been entered.

Thanx.


Nov 19 '05 #2
thanx I'll try to convert this in VB.NET.

"Brock Allen" wrote:
Sure, in Page_Load:

if (ConditionsMet)
{
RequiredFieldValidator val = new RequiredFieldValidator();
val.ControlToValidate = "idOfOtherControl";
val.Text = "* Required";
val.ErrorMessage = "You must provide a value for my other control";
somePlaceHolderInYourPage.Controls.Add(val);
}

So this assumes you have some <asp:PlaceHolder> or other control positioned
in the page where you want to add in your validation control.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Is there a way to, based on the selection of another control, add a
required field validator to another field (code behind vb.net)? I
don't want the field to be required unless a checkbox or date field
has been entered.

Thanx.


Nov 19 '05 #3
If ConditionsMet Then
dim va as new RequiredFieldValidator() ';
val.ControlToValidate = "idOfOtherControl" ';
val.Text = "* Required" ';
val.ErrorMessage = "You must provide a value for my other control" ';
somePlaceHolderInYourPage.Controls.Add(val) ';
End If
-Brock
DevelopMentor
http://staff.develop.com/ballen
thanx I'll try to convert this in VB.NET.

"Brock Allen" wrote:
Sure, in Page_Load:

if (ConditionsMet)
{
RequiredFieldValidator val = new RequiredFieldValidator();
val.ControlToValidate = "idOfOtherControl";
val.Text = "* Required";
val.ErrorMessage = "You must provide a value for my other control";
somePlaceHolderInYourPage.Controls.Add(val);
}
So this assumes you have some <asp:PlaceHolder> or other control
positioned in the page where you want to add in your validation
control.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Is there a way to, based on the selection of another control, add a
required field validator to another field (code behind vb.net)? I
don't want the field to be required unless a checkbox or date field
has been entered.

Thanx.


Nov 19 '05 #4

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

Similar topics

1
by: JZ | last post by:
I use Webware and FormKit. I have a problem with dynamic added field to the form. The following code creates one input field and two submit buttons. I would like to add more (up to 4) input fields...
1
by: psparago | last post by:
I have developed a tab user control in which each tab is itself a user control and the tab selection control is a datalist. Each tabbed user control has zero or more validator controls on it. The...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
1
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
7
by: Abraham Luna | last post by:
how do i stop the dynamic validators from breaking explorer if i use a dynamic validator and move to a different control it breaks explorer and i can type in the page when i'm not supposed to....
3
by: rgparkins | last post by:
Hi I am currently having problems with Validators in a user control. I am creating a wizard sign-up process which have the allocated step (hyperlinks" at the top of the page. A user can also...
3
by: Wayne Sepega | last post by:
I have inherited from System.Web.UI.WebControls and overrode the OnRender of my new button. In the on render I generate some JavaScript and add it as an attribute as follows: ...
0
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validators to each control as needed, but the validators are not firing when I click...
2
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validator to each control as needed, but the validators are not firing when I click submit....
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.