Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.aspnet.buildingcontrols
Validators and IDs of other controls
Nathan Sokalski
2/12/2008 7:54:00 PM
I have a validator control that I wrote by inheriting from the BaseValidator
class. One of the properties of my class is the id of another control which
will determine whether or not the ControlToValidate needs validated (this
property is named conditionid). When I attempt to access this control, I use
the following statement:
needsvalidated = CType(Me.Page.FindControl(Me.conditionid),
CheckBox).Checked
However, when I submit the form, I recieve the following error, which points
to the line in my code mentioned above:
Object reference not set to an instance of an object.
I know that the value for Me.conditionid is there, because I checked it
while debugging. I believe the control with that id is available, because it
is added declaratively in the *.aspx file. What could be the problem? (I
don't know if it makes a difference for this problem, but I would like to
note also that I am using a Master page, but none of the stuff I have
mentioned is in the Master page; the line of code I mentioned above is from
the validator that inherits BaseValidator, and the control that has the id
Me.conditionid is in the *.aspx page) Any help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansok...
2 Answers
bruce barker
2/12/2008 9:06:00 PM
0
Page.FindControl only searches the pages Control collection. But a Control in
Page collection can have its own. If you use a Master Page, then the master
page control is in the Page collection. the master control has content
controls. In the content controls are collections of the control defined in
the content area. if you use server tables or repeators then you have more
control collection.
with validators the standard pattern is to require the controls and the
validators have the same naming container, so your code should be:
needsvalidated = CType(Me.FindControl(Me.conditionid), CheckBox).Checked
though you really should check if find returns a null.
-- bruce (sqlwork.com)
"Nathan Sokalski" wrote:
> I have a validator control that I wrote by inheriting from the BaseValidator
> class. One of the properties of my class is the id of another control which
> will determine whether or not the ControlToValidate needs validated (this
> property is named conditionid). When I attempt to access this control, I use
> the following statement:
>
> needsvalidated = CType(Me.Page.FindControl(Me.conditionid),
> CheckBox).Checked
>
> However, when I submit the form, I recieve the following error, which points
> to the line in my code mentioned above:
>
> Object reference not set to an instance of an object.
>
> I know that the value for Me.conditionid is there, because I checked it
> while debugging. I believe the control with that id is available, because it
> is added declaratively in the *.aspx file. What could be the problem? (I
> don't know if it makes a difference for this problem, but I would like to
> note also that I am using a Master page, but none of the stuff I have
> mentioned is in the Master page; the line of code I mentioned above is from
> the validator that inherits BaseValidator, and the control that has the id
> Me.conditionid is in the *.aspx page) Any help would be appreciated. Thanks.
> --
> Nathan Sokalski
> njsokalski@hotmail.com
>
http://www.nathansok...
>
>
>
Nathan Sokalski
2/12/2008 10:11:00 PM
0
Thanks! That worked great! It' nice to have people like you that give quick,
yet complete, answers.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansok...
"bruce barker" <brucebarker@discussions.microsoft.com> wrote in message
news:41573AB1-79A6-404A-B67F-77951C03B8C1@microsoft.com...
> Page.FindControl only searches the pages Control collection. But a Control
> in
> Page collection can have its own. If you use a Master Page, then the
> master
> page control is in the Page collection. the master control has content
> controls. In the content controls are collections of the control defined
> in
> the content area. if you use server tables or repeators then you have more
> control collection.
>
> with validators the standard pattern is to require the controls and the
> validators have the same naming container, so your code should be:
>
> needsvalidated = CType(Me.FindControl(Me.conditionid), CheckBox).Checked
>
> though you really should check if find returns a null.
>
> -- bruce (sqlwork.com)
>
>
> "Nathan Sokalski" wrote:
>
>> I have a validator control that I wrote by inheriting from the
>> BaseValidator
>> class. One of the properties of my class is the id of another control
>> which
>> will determine whether or not the ControlToValidate needs validated (this
>> property is named conditionid). When I attempt to access this control, I
>> use
>> the following statement:
>>
>> needsvalidated = CType(Me.Page.FindControl(Me.conditionid),
>> CheckBox).Checked
>>
>> However, when I submit the form, I recieve the following error, which
>> points
>> to the line in my code mentioned above:
>>
>> Object reference not set to an instance of an object.
>>
>> I know that the value for Me.conditionid is there, because I checked it
>> while debugging. I believe the control with that id is available, because
>> it
>> is added declaratively in the *.aspx file. What could be the problem? (I
>> don't know if it makes a difference for this problem, but I would like to
>> note also that I am using a Master page, but none of the stuff I have
>> mentioned is in the Master page; the line of code I mentioned above is
>> from
>> the validator that inherits BaseValidator, and the control that has the
>> id
>> Me.conditionid is in the *.aspx page) Any help would be appreciated.
>> Thanks.
>> --
>> Nathan Sokalski
>> njsokalski@hotmail.com
>>
http://www.nathansok...
>>
>>
>>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Validators and IDs of other controls
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password