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 and Free Setup - ASP.NET Web Hosting



Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 4/12/2005 11:25:23 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 7 Views: 141 Favorited: 0 Favorite
8 Items, 1 Pages 1 |< << Go >> >|
Martin Payne
Asp.Net User
composite control with RequiredFieldValidator4/12/2005 11:25:23 AM

0/0

I am trying to create a composite control that contains a RequiredFieldValidator but I'm having a few problems.  The CreateChildControls method looks something like this -

Controls.Add(New TextBox())
Dim rfv as New RequiredFieldValidator()
rfv.ControlToValidate = Me.Controls(0).UniqueId
Controls.Add(rfv)

When I run it I get an error -

Unable to find control id 'mff1$ct100' referenced by the 'ControlToValidate property of

mff1$ct100 is the value of the name property of the textbox if I render the page without the RequiredFieldValidator (at which time it renders without issue).

There must be some way of creating a composite control containing a RequiredFieldValidator, what's the secret?

Cheers

Martin 

 


"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."

Douglas Adams
bmains
Asp.Net User
Re: composite control with RequiredFieldValidator4/12/2005 11:40:40 AM

0/0

Try using the ID or the ClientID properties instead...  There isn't any control ID for the control specifically, because the ID should be TextBox<n>.
Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Martin Payne
Asp.Net User
Re: composite control with RequiredFieldValidator4/12/2005 12:35:01 PM

0/0

I found my problem, although I'm not sure why.  My class was implementing the iNamingContainer template.  When I removed that it worked with both UniqueId and ClientId (btw, neither ClientId or ID worked until I removed the iNamingContainer thing).

Thanks for your help.  I will muck around with the ability to use multiple instances of my class on the same page tomorrow (I suspect that I will have problems now that the iNamingContainer is gone Sad [:(]).

Cheers

Martin


"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."

Douglas Adams
hlaford
Asp.Net User
Re: composite control with RequiredFieldValidator4/12/2005 2:54:20 PM

0/0

using a validator in a custom control requires the validator and the validated controls be in the same naming container, whether or not that naming container is the custom control.  if you remove the INamingContainer interface, you will need to perform the same logic yourself that you get for free: providing unique IDs for child controls.  i do just that and all my controls work well; however, i am currently having issues when my controls are embedded in several layers of user controls.  i don't know if it's really caused by a lack of a naming container, but there may be some hidden risk to doing things my way.
master4eva
Asp.Net User
Re: composite control with RequiredFieldValidator4/12/2005 8:20:19 PM

0/0

This should work:

<code>
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class AComposite
    Inherits System.Web.UI.Control
    Implements INamingContainer

    Protected ReadOnly txtSomeTextBox As New TextBox()
    Protected ReadOnly rfvSomeTextBox As New RequiredFieldValidator()

    Protected Overrides Sub CreateChildControls()
        Me.Controls.Add(Me.txtSomeTextBox)
        Me.Controls.Add(Me.rfvSomeTextBox)

        Me.rfvSomeTextBox.ControlToValidate = Me.txtSomeTextBox.ID
    End Sub
End Class
</code>

-- Justin Lovell
Martin Payne
Asp.Net User
Re: composite control with RequiredFieldValidator4/13/2005 3:20:19 AM

0/0

master4eva,

Adding the validator to the controls collection before setting its ControlToValidate property was something I hadn't yet tried.  Unfortunately, after trying it I find the same problems.  Does it work for you?

Thanks

Martin


"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."

Douglas Adams
master4eva
Asp.Net User
Re: composite control with RequiredFieldValidator4/13/2005 5:20:28 PM

0/0

Oops. Forgot one thing. Remember that EnsureChildControls() (which in turn calls the CreateChildControls() method) is only called during OnPreRender - after all the validation logic has fired in the page. The thing is, you have to put your validator on the page before the logic that fires... and there are two locations in the page life cycle to do that: OnInit and OnLoad. So either two will be alright:

Protected Overrides Sub OnInit(e As EventArgs)
   MyBase.OnInit(e)
   Me.EnsureChildControls()
End Sub

' or

Protected Overrides Sub OnLoad(e As EventArgs)
   MyBase.OnLoad(e)
   Me.EnsureChildControls()
End Sub

-- Justin Lovell
Martin Payne
Asp.Net User
Re: composite control with RequiredFieldValidator4/15/2005 2:36:21 AM

0/0

Perfect !  I put it in the OnInit and it works.

Many thanks,

Martin


"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."

Douglas Adams
8 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.NET by Example Authors: Steven A. Smith, Pages: 552, Published: 2002
Developing Microsoft ASP.NET Server Controls and Components Authors: Nikhil Kothari, Vandana Datye, Pages: 689, Published: 2002
ASP.NET AJAX Programming Tricks Authors: Matthew David Ellis, Matthew Ellis, Pages: 388, Published: 2007
Designing Microsoft ASP.NET Applications Authors: Douglas J. Reilly, Pages: 402, Published: 2001
Visual Basic .NET Developer's Guide to ASP.NET, XML, and ADO.NET Authors: Jeffrey P. McManus, Chris Kinsman, Pages: 592, Published: 2002
Beginning ASP.NET 1.1 with Visual C# .NET 2003 Authors: Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry, Pages: 888, Published: 2004
Programming ASP.NET: Building Web Applications and Services with ASP.NET 2.0 Authors: Jesse Liberty, Dan Hurwitz, Pages: 930, Published: 2005
Inside Server-based Applications Authors: Douglas J. Reilly, Pages: 614, Published: 1999

Web:
Composite Control - RadioButtonList - RequiredFieldValidator ... I created a Textbox and RequiredFieldValidator CompositeControl which works fine and complied this into a working .dll file for my ASP. ...
Problem with RequiredFieldValidator in custom (C#) control Old 01-13-2006, 01:13 PM. Default Problem with RequiredFieldValidator in custom (C#) control. I have a composite control rougly like that:: ...
OurCurrentFuture.com - All posts tagged 'requiredfieldvalidator' Aug 22, 2008 ... 11: public abstract class RequiredInput : CompositeControl 12: { 13: #region " Members " 14: 15: protected RequiredFieldValidator ...
Composite Web Control Example NET server control. A composite control uses child controls to create a user ... the Button control for the postback event, and the RequiredFieldValidator ...
Sasha Sydoruk » HowTo - CompositeControl with a TextBox and a ... Jan 19, 2007 ... The composite control will automatically add the required validators and will ... TextBox _textBox = null; protected RequiredFieldValidator ...
Adding validators to CompositeControl - .NET ASP add some validation to my custom control, it's a descendant of CompositeControl. I get the exception: Unable to find control id ...
CodeProject: Building an ASP.NET custom web control: a textbox and ... //Process req and add it to the composite control // LabelRadioButtonList req = new RequiredFieldValidator(); req.ControlToValidate = this.ID; ...
RequiredTextBox - Composite Control Or Inherit From Textbox - ASP ... RequiredFieldValidator validator1 = new RequiredFieldValidator(); ... } The composite control required a lot more code and you also ...
Composite Control Property Setting Problem I have built a simple composite control that consists of a textbox, requiredfieldvalidator and rangevalidator. ...
CompositeControl vs User Controls - which is less hassle now? Oct 20, 2005 ... Now that we have the CompositeControl to inherit from in Asp.Net 2, ... RequiredFieldValidator validator = new RequiredFieldValidator(); ...












format date time

error 17 argument '2': cannot convert from 'system.web.ui.webcontrols.fontsize' to 'float'

problem with dynamically created objects

convert ascii to unicode

calling .ascx user control from a page under another domain

how to store image url form .net to xml

closing web form with a timer

pease help!! - web user control loaded with loadcontrol() looses event wireups and event functionality?

c# code behind variable in client side javascript

overview of asp.net program cycle

long lines in emails

validationsummary

no items are viewable on code behind

cannot assign text and textboxes to string variable

styling a button

multiple file download in client side

input strings and passing variables to another page

.net with frames

formatting date in a repeater

trouble modifying text after copying items between listboxes

on getting user credentials(user name) but setting iis as "allow anonymous access" - from a struggling intern

problem with login page ?

retrieving the values of a hyperlink querystring

uploading files that are larger than maxrequestlength

addhandler issue

creating a control which can contain asp.net&html objects or controls

field validations

fundamental problem with event firing - please help

depending dropdown-lists

validating negative value in textbox

  Privacy | Contact Us
All Times Are GMT