Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Problem with FindControl


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sun, 22 Dec 2002 05:40:16
Hello Everyone and thanks for your help in advance.  I am having problems 
using an OnItemDataBound subroutine in a datalist.  Within the datalist, 
I have a button called "btnPunchClock".  I want to be able to set the 
text and command arguments programmatically depending on certain 
criteris.  The OnItemDataBound calls a subroutine called "CheckStatus".  
The code for this sub is as follows:

Sub CheckStatus(ByVal objSender As Object, ByVal objArgs As 
DataListItemEventArgs)

'objArgs.Item.DataItem returns the data for this row of items
Dim objRowVals As DataRowView = CType (Args.Item.DataItem, DataRowView)

        Dim objButton As Button = CType(objArgs.Item.FindControl
("btnPunchClock"), Button)
        objButton.Text = "Clock Out"

    End Sub

However when I run the program, I get an error:

Object reference not set to an instance of an object

I have used this technique in the past with good results, but can't seem 
to understand why this won't work now.  Any help would be greatly 
appreciated.  Thanks.
Message #2 by "Carole D. Sullivan" <carolesullivan@e...> on Mon, 23 Dec 2002 16:05:20
Often when I get that message it's because I should have used 'dim xxx as 
NEW zzz'.  

> Hello Everyone and thanks for your help in advance.  I am having 
problems 
u> sing an OnItemDataBound subroutine in a datalist.  Within the 
datalist, 
I>  have a button called "btnPunchClock".  I want to be able to set the 
t> ext and command arguments programmatically depending on certain 
c> riteris.  The OnItemDataBound calls a subroutine 
called "CheckStatus".  
T> he code for this sub is as follows:

> Sub CheckStatus(ByVal objSender As Object, ByVal objArgs As 
D> ataListItemEventArgs)

> 'objArgs.Item.DataItem returns the data for this row of items
D> im objRowVals As DataRowView = CType (Args.Item.DataItem, DataRowView)

>         Dim objButton As Button = CType(objArgs.Item.FindControl
(> "btnPunchClock"), Button)
 >        objButton.Text = "Clock Out"

>     End Sub

> However when I run the program, I get an error:

> Object reference not set to an instance of an object

> I have used this technique in the past with good results, but can't 
seem 
t> o understand why this won't work now.  Any help would be greatly 
a> ppreciated.  Thanks.
Message #3 by "Hugh McLaughlin" <hugh@k...> on Mon, 23 Dec 2002 16:59:44
Actually, I tried that without success.

> Often when I get that message it's because I should have used 'dim xxx 
as 
N> EW zzz'.  

> > Hello Everyone and thanks for your help in advance.  I am having 
p> roblems 
u> > sing an OnItemDataBound subroutine in a datalist.  Within the 
d> atalist, 
I> >  have a button called "btnPunchClock".  I want to be able to set the 
t> > ext and command arguments programmatically depending on certain 
c> > riteris.  The OnItemDataBound calls a subroutine 
c> alled "CheckStatus".  
T> > he code for this sub is as follows:

> > Sub CheckStatus(ByVal objSender As Object, ByVal objArgs As 
D> > ataListItemEventArgs)

> > 'objArgs.Item.DataItem returns the data for this row of items
D> > im objRowVals As DataRowView = CType (Args.Item.DataItem, DataRowView)

> >         Dim objButton As Button = CType(objArgs.Item.FindControl
(> > "btnPunchClock"), Button)
 > >        objButton.Text = "Clock Out"

> >     End Sub

> > However when I run the program, I get an error:

> > Object reference not set to an instance of an object

> > I have used this technique in the past with good results, but can't 
s> eem 
t> > o understand why this won't work now.  Any help would be greatly 
a> > ppreciated.  Thanks.

  Return to Index