CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 6/17/2003 3:01:08 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 6 Views: 23 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
7 Items, 1 Pages 1 |< << Go >> >|
hlaford
Asp.Net User
building auto-validated textbox using inheritance6/17/2003 3:01:08 PM

0/0

so i figured out how to build the whole control using inheritance, including validators. i have an issue when attempting to perform validation in that

1. if the control implements INamingContainer, the validators can't find the control since it attempts to find the ControlToValidate below the NamingContainer.
2. if the control does not implement INamingContainer, the validators can't find the textbox if it isn't directly under the naming container--they don't seem to perform a recursive lookup.

has anyone figured out how to do this part of it?
perryj
Asp.Net User
Re: building auto-validated textbox using inheritance6/17/2003 9:11:13 PM

0/0

Not sure if I understand all of your setup or not? I'm assuming you are using a Composite Control to accomplish this. I'm just trying to think thru the problem in my head and I think something like this would work for CreateChildControls:


protected override void CreateChildControls()
{
Controls.Clear();

valRequired = new RequiredFieldValidator();
textBox1 = new TextBox();

textBox1.ID = "Text1";
valRequired.ControlToValidate = textBox1.ID;

Controls.Add(textBox1);
Controls.Add(valRequired);
}


Does this help any? Let us know back here if you can't figure it out.

Jason
hlaford
Asp.Net User
Re: building auto-validated textbox using inheritance6/17/2003 10:11:50 PM

0/0

i have it working already as a composite control, but i'd like to use inheritance. i currently have a required field validator and a regex validator in it with a textbox. there's other junk in there, but that's outside the problem domain for now.

i keep getting stuck on the validation model in .NET. if my new textbox (based on inheritance) implements INamingContainer, the validators can't find the textbox since they start at the naming container and search immediately under it for the control to validate.

if i remove INamingContainer, the validators can't find the control to validate unless it is immediately under the new naming container.

i think it may just be a fundamental problem with the validation model since i can't just provide a reference to the control to validate. it's nice, i suppose, to enable the validator set up in the ASPX using a string identifier...

now that i think about it, maybe the "favor composition over inheritance" gods are just trying to send me a message.
perryj
Asp.Net User
Re: building auto-validated textbox using inheritance6/17/2003 10:18:45 PM

0/0

Could you post some example code? Maybe you are just missing some small detail?

Without looking over your specific example, I'm not sure I'm gonna understand the whole issue.
hlaford
Asp.Net User
Re: building auto-validated textbox using inheritance6/18/2003 2:56:38 AM

0/0

i built a dumbed-down version of my control to post it here and it seems to be working just fine. i figure i will attack its overall construction in pieces. i must have introduced some breaking code.


using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Controls {
public class RequiredTextBox : TextBox {
private RequiredFieldValidator requiredValidator;

public bool Required {
get {
EnsureChildControls();
return requiredValidator.Visible;
}
set {
EnsureChildControls();
requiredValidator.Visible = value;
}
}

protected override ControlCollection CreateControlCollection() {
return new ControlCollection(this);
}

protected override void CreateChildControls() {
base.CreateChildControls();

requiredValidator = new RequiredFieldValidator();
Controls.Add(requiredValidator);
requiredValidator.ID = this.UniqueID + "_req";
requiredValidator.ControlToValidate = this.ID;
requiredValidator.ErrorMessage = "required!";
}

protected override void Render(HtmlTextWriter writer) {
writer.RenderBeginTag(HtmlTextWriterTag.Nobr);
base.Render(writer);
RenderChildren(writer);
writer.RenderEndTag();
}
}
}
jerchap
Asp.Net User
Re: building auto-validated textbox using inheritance5/26/2004 6:19:49 PM

0/0

Was there a solution to this problem? I'm having the exact same issue.
hlaford
Asp.Net User
Re: building auto-validated textbox using inheritance5/26/2004 9:38:31 PM

0/0

a validator and its controltovalidate must be within the same NamingContainer for the relationship to be recognized. if the textbox doesn't implement INamingContainer, but i still code it to prefix the child validator ID with its UniqueID, the relationship survives.

also, generally speaking, if the control you want to give children doesn't support it out of the box, just override the CreateControlCollection method to create a new one.
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
building auto-validated textbox using inheritance - ASP.NET Forums building auto-validated textbox using inheritance. Last post 05-26-2004 6:26 PM by hlaford. 6 replies. Sort Posts: ...
CoDe Magazine - Article: Using Your Inheritance Well, have you had trouble creating forms before you thought of them as using inheritance? Did you have difficulty dropping textboxes onto the design ...
Safari Books Online - 0672324075 - Visual Basic® .NET Power Coding Using an event handler is convenient for general purpose validation; ... This control is a great building block for specifically typed TextBox controls. ...
Cornerstones utvecklarblogg : september 2007 - Inlägg Using mediation I could defer from using inheritance and did not have to add extra ... It also enabled reuse of the validation for any kind of textbox, ...
The Three Steps of Building an ASP.NET Validator Control Sep 22, 2008 ... Using them will dramatically reduce the amount of validation code and will ... function that will be called to validate the TextBox Page. ...
microsoft visual basic 6.0 and textbox Resources | TechRepublic Find out how you can automate the data validation process in VB6 using the ... Inheritance and Interfaces: Only a small percentage of Visual Basic 6.0 ...
Inside Microsoft: Building a Forms Generator using Code DOM By design, this control can only be a TextBox if the column is not ... << Previous: Using RegularExpressionValidator and RequiredFieldValidator to validate ...
CodeGuru: TextBox Also shows how to auto-scroll the text box as you add items. Uses the RtlMoveMemory and SendMessage ... Lost Focus / Got Focus Event--text box validation ...
InformIT: .NET Reference Guide > Validating User Input in ASP.NET ... You can compare input against a specific value using the ... When you press the button, the page is validated. Since the text box is a required field and ...
Building a Scalable Business Process Automation Engine Using ... When the user clicks Apply, the ticket fields are validated and the ticket is saved using the Ticket object described in CoreWorkflow system. ...




Search This Site:










debugging client side !!

generate an html page dynamically.

problem with child control parsing for container control

problem with dynamic checkbox controls

custome controls, javascript, and firefox/mozilla

treeview with plain text instead of hyperlinks

using an expression validator in my custom control

dynamic controls issue

arraylist & custom controls

url editor

dedicated server or virtual dedicated server

problem of calling postback eventhandlers.

can't access usercontrol from codebehind

visual web developer express - who can host the sites?

passing parameters to dynamically added user control

how can know class of a webcontrol

can i build my own webcontrols?

custom tags inside a control

gate.com

problem with font property of custom web control

how to reload a page(webform1.aspx) on click of a button in .ascx page

strange access denied error

custom control problems!!!

dynamically added user control disapearing on postback

embeding a javascript file in the dll

building server controls in whidbey?

composite control - property cascading

how is this for colocation costs...

how-to: bind custom control to xml

user controls containing other user controls

  Privacy | Contact Us
All Times Are GMT