Determining the container of a Control

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I am writing a Validator (a control that inherits from
System.Web.UI.WebControls.BaseValidator), and I need to get a reference to
the Control specified by the ControlToValidate property. I have tried using:

Me.Page.FindControl(Me.ControlToValidate)

But this is returning the value Nothing. I think the reason for this is that
my test page is using a Master Page, but regardless of the reason I
obviously need code that will return the correct value regardless of where
it is being used. After a little research, I found that the Validator and
ControlToValidate must be in the same container (and in every scenario I
have ever seen they are anyway, including my test page). In my case, this
would be the ContentPlaceHolder, but for other people the container might be
something else (Because this is a Control I need something that will work
for everyone). Is there a property or method that can tell me the container
of ControlToValidate (I am thinking if I use the FindControl method of the
container, it should work)? Or, if somebody knows a better way to get a
reference to the Control specified by ControlToValidate, that would be good
as well. Thanks.
 
B

bruce barker

your validator should use this.FindControl() (me in vb i think). this
will start the search from the validators naming container, instead of
using the pages.

if the control and the validator are not in the same naming container,
then set the ControlToValidate to the UniqueID (in code)

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top