Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Adding validation controls programmatically

Thread Tools

Adding validation controls programmatically

D Sheldon
Posts: n/a
I am creating a server control that adds web controls (i.e. textboxes, etc) to a form. I use HtmlTable to build the table and insert the controls. Now I want to add validators to the textbox. Here is the code that I am using:

bool lastnamerequired=false;
public bool LastNameRequired
get{return lastnamerequired;}
set{lastnamerequired = value;}

System.Web.UI.WebControls.RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ControlToValidate = "sFirstName";
rfv.Display = ValidatorDisplay.Dynamic;
rfv.Text = "";
rfv.ErrorMessage = "Required";
rfv.EnableClientScript = true;
rfv.ID = "rfvFirstName";

This code seems to only add the word "Required" to my form when rendered. It's not dynamic nor does it go away when the field is valid.

Any ideas?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Controls Programmatically Chakravarti Mukesh ASP .Net 3 02-14-2013 08:39 AM
Programmatically enabling Validation Controls Jav ASP .Net Web Controls 1 09-04-2006 10:21 AM
CreateChildControls() when adding controls programmatically ASP .Net 0 06-19-2006 08:34 AM
Adding controls programmatically. Tim Marsden ASP .Net 2 05-25-2004 03:33 AM
Adding validation controls programmatically =?Utf-8?B?RCBTaGVsZG9u?= ASP .Net 2 05-11-2004 07:16 PM