Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Adding validation controls programmatically

 
 
=?Utf-8?B?RCBTaGVsZG9u?=
Guest
Posts: n/a
 
      05-11-2004
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 LastNameRequire

get{return lastnamerequired;
set{lastnamerequired = value;


if(lastnamerequired

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"
td.Controls.Add(rfv)


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
 
 
 
 
Peter Blum
Guest
Posts: n/a
 
      05-11-2004
Are you adding these controls in the PreRender stage? Validators must be
setup prior to PreRender because they have to be able to run their own
OnPreRender method. That method outputs the necessary javascript for
validation and converts the IsValid property into the shown or hidden <span>
tag as the page is initially drawn.

--- Peter Blum
www.PeterBlum.com
Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"D Sheldon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;}
> }
>
> if(lastnamerequired)
> {
> 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";
> td.Controls.Add(rfv);
> }
>
> 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
 
 
 
 
=?Utf-8?B?RCBTaGVsZG9u?=
Guest
Posts: n/a
 
      05-11-2004
That would make sense. Can you show me an example to illustrate

Thanks.
 
Reply With Quote
 
 
 
Reply

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 mark.norgate@gmail.com 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 D Sheldon ASP .Net Building Controls 0 05-11-2004 06:31 PM



Advertisments