473,805 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 RequiredFieldVa lidator for itself.
No matter how I add the validator within the control it never seems to
show up in the page.

protected override void CreateChildCont rols()
{
if(m_bRequiredF ield)
{
RequiredFieldVa lidator rfv = new RequiredFieldVa lidator ();
rfv.ControlToVa lidate = this.ID;
rfv.Display = ValidatorDispla y.Dynamic;
rfv.ErrorMessag e = UserFieldName + " is required.";
this.Controls.A dd(rfv);
}
base.CreateChil dControls ();
}
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(Eve ntArgs e)
{
RequiredFieldVa lidator rvf = new RequiredFieldVa lidator ();
rvf.ID=this.Cli entID + "_Validator ";
Page.Validators .Add(rvf);
base.OnPreRende r (e);
}
protected override void Render(HtmlText Writer writer)
{
base.Render (writer);
if(m_bRequiredF ield)
{
writer.Write("< span id=\""+this.Cli entID+"_Validat or\" " +
"controltovalid ate=\"" + this.ClientID + "\" " +
"errormessage=\ ""+UserFieldNam e+" is required\" display=\"Dynam ic\"
evaluationfunct ion=\"RequiredF ieldValidatorEv aluateIsValid\" " +
"initialvalue=\ "\" style=\"color:R ed;display:none ;\">*</span>");
}
}
Any ideas would be appreciated.

Nov 19 '05 #1
0 1063

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

Similar topics

1
3806
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
3923
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 javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I did some work on was having the control implement the IValidator interface and basically recreating...
2
1646
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 suggestions appreciated. Thanks!
1
1282
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 works great until I want to use a validator. Any validators added to the page do not fire. I can leave a required textbox blank, and the code happily chugs through processing the button click code. After some research, I've found that some...
3
1706
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 validators are working for controls OUTSIDE the panels.. help please? And, thank you. J.
7
2479
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 each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
2
6480
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) In Page_load, Dim Email As New Label
0
1756
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 am filling the this textbox , it works fine when i am in development server. But whenever i moved my code to hosting server the required field validator stops the form being submitted. If I remove the readonly property on hosting server then it...
1
1805
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 each textbox.
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10103
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9179
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.