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

Adding validation controls programmatically

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

Nov 18 '05 #1
2 4831
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"D Sheldon" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
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?

Nov 18 '05 #2
That would make sense. Can you show me an example to illustrate

Thanks.
Nov 18 '05 #3

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

Similar topics

3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: Eric Maia | last post by:
I have two UserControls I am using in a form. These are each also used separately in two other forms. The structure is essentially this: CourseUserControl.ascx - select or enter a course...
1
by: Jack | last post by:
Hi, I have a page with a repeater control that contains textboxes. I'm trying to create a validation class that is called by my page. A method in this class iterates through all the controls...
7
by: Jo Inferis | last post by:
For reasons that are unlikely to become clear at the moment, I have a page with some validation controls on it which opens a dialog. The dialog does *stuff* and then closes with a call to : ...
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then...
1
by: Mukesh | last post by:
Currently i am developing a web application using asp.net1.1. I have developed several user control for this application . I am using validator in such user control. My problem is that...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
4
by: alun65 | last post by:
I'm attempting to programmatically build up some HTML in the code behind. Like so: // Create Hyperlink HyperLink link = new HyperLink(); link.NavigateUrl = "nice cat"; link.Text = "Cats...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...
0
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...

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.