473,398 Members | 2,335 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,398 software developers and data experts.

Inherited Textbox required validator

I have a control which inherits from TextBox and supplies some
additional data functionality. I was hoping to include a boolean flag
"Required" that can be set in the designer. When the flag is set to
True the control should include a RequiredFieldValidator for itself.
No matter how I add the validator within the control it never seems to
show up in the page.

protected override void CreateChildControls()
{
if(m_bRequiredField)
{
RequiredFieldValidator rfv = new RequiredFieldValidator ();
rfv.ControlToValidate = this.ID;
rfv.Display = ValidatorDisplay.Dynamic;
rfv.ErrorMessage = UserFieldName + " is required.";
this.Controls.Add(rfv);
}
base.CreateChildControls ();
}
I would like to avoid creating a composite control. I have also tried
other events such as PreRender and DataBind.

I even tried hacking the text HTML for the validator in the Render and
add an empty validator to the Page.Validators with the same clientID.
But the page doesn't seem to register it.

my attempted hack

protected override void OnPreRender(EventArgs e)
{
RequiredFieldValidator rvf = new RequiredFieldValidator ();
rvf.ID=this.ClientID + "_Validator";
Page.Validators.Add(rvf);
base.OnPreRender (e);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render (writer);
if(m_bRequiredField)
{
writer.Write("<span id=\""+this.ClientID+"_Validator\" " +
"controltovalidate=\"" + this.ClientID + "\" " +
"errormessage=\""+UserFieldName+" is required\" display=\"Dynamic\"
evaluationfunction=\"RequiredFieldValidatorEvaluat eIsValid\" " +
"initialvalue=\"\" style=\"color:Red;display:none;\">*</span>");
}
}
Any ideas would be appreciated.

Nov 19 '05 #1
0 1041

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

Similar topics

1
by: Philip Wagenaar | last post by:
As far as I can tell it is not possible to make a RadioButtonList with a textbox as an Item. Ie. 1. Yes 2. No 3. Other would be the textarea.
2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
2
by: Ned | last post by:
I am trying to use a CustomValidator on a textbox. The Validator uses a client-side funtion but it doesn't run if the textbox is empty. If there is data in the text box it runs fine. Any...
1
by: Shaun | last post by:
I am using a base page (I think they're also called master pages) as a base that my webforms inherit from. The base page controls formating and common functions used throughout the site. This all...
3
by: JJ_377 | last post by:
how do I do this: textbox is in a panel control. the required field validator doesn't work. I tried putting the required field validator inside the panel and it doesn't work there either. my...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
2
by: Christina | last post by:
Hello !! I am creating a dynamic textbox and want to validate it using the requiredfieldvalidator. These are the steps which I tried: ==================================================== 1)...
0
by: nimeshdotnet | last post by:
Hi All, I have a textbox whose readonly property is set to true. This textbox is also guarded by a required field validator. What i m doing that I have a calendar control whose on date selection i...
1
by: =?Utf-8?B?R2hpc3Rvcw==?= | last post by:
Hi all, Does anyone know a place where I can buy or see how to extend the aps.net 2.0 Textbox with a ready to use validator (regEx, Required...). I'm tired to always put 2-3 validators for...
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...
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...
0
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...

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.