Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > FindControl in Class

Reply
Thread Tools

FindControl in Class

 
 
MRW
Guest
Posts: n/a
 
      09-04-2006
Hello!

I have a problem, I can't seem to solve.

I'm making a class in my page that will hold the members of a FormView,
so I can access them freely throughout the several functions and
subroutines, without having to redefine them every function/subroutine.

I ran into a problem when trying to define a GridView in that FormView
and I was hoping somebody can help me on this, since I'm going a tad
crazy. Here's part of the code:

---
Partial Public Class FM
Inherits System.Web.UI.Page

Public FV_Customer As FormView
Public GV_PhoneNumbers As GridView =
FV_Customer.FindControl("GV_PhoneNumbers")

---

I keep getting an "Object reference not set to an instance of an
object. " for the GridView. Can anybody help?

Thanks in advance!

 
Reply With Quote
 
 
 
 
RHIZOME
Guest
Posts: n/a
 
      09-04-2006
Declare new with Public FV_Customer As FormView

e.g. Public FV_Customer As New FormView



MRW wrote:
> Hello!
>
> I have a problem, I can't seem to solve.
>
> I'm making a class in my page that will hold the members of a FormView,
> so I can access them freely throughout the several functions and
> subroutines, without having to redefine them every function/subroutine.
>
> I ran into a problem when trying to define a GridView in that FormView
> and I was hoping somebody can help me on this, since I'm going a tad
> crazy. Here's part of the code:
>
> ---
> Partial Public Class FM
> Inherits System.Web.UI.Page
>
> Public FV_Customer As FormView
> Public GV_PhoneNumbers As GridView =
> FV_Customer.FindControl("GV_PhoneNumbers")
>
> ---
>
> I keep getting an "Object reference not set to an instance of an
> object. " for the GridView. Can anybody help?
>
> Thanks in advance!


 
Reply With Quote
 
 
 
 
MRW
Guest
Posts: n/a
 
      09-04-2006
What the???

Mmm...

Okay... can you explain exactly what that "New" does that made it work?

Thanks for the help!

RHIZOME wrote:
> Declare new with Public FV_Customer As FormView
>
> e.g. Public FV_Customer As New FormView
>
>
>
> MRW wrote:
> > Hello!
> >
> > I have a problem, I can't seem to solve.
> >
> > I'm making a class in my page that will hold the members of a FormView,
> > so I can access them freely throughout the several functions and
> > subroutines, without having to redefine them every function/subroutine.
> >
> > I ran into a problem when trying to define a GridView in that FormView
> > and I was hoping somebody can help me on this, since I'm going a tad
> > crazy. Here's part of the code:
> >
> > ---
> > Partial Public Class FM
> > Inherits System.Web.UI.Page
> >
> > Public FV_Customer As FormView
> > Public GV_PhoneNumbers As GridView =
> > FV_Customer.FindControl("GV_PhoneNumbers")
> >
> > ---
> >
> > I keep getting an "Object reference not set to an instance of an
> > object. " for the GridView. Can anybody help?
> >
> > Thanks in advance!


 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-04-2006
If you have members on aspx page, and you reference them, you *never* create
new instances of them yourself, unless you also add them to the Controls
collection e.g create dynamical controls. If control is declared on aspx,
page parser takes care of providing the plumbing to instantiate a control.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


"RHIZOME" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Declare new with Public FV_Customer As FormView
>
> e.g. Public FV_Customer As New FormView
>
>
>
> MRW wrote:
>> Hello!
>>
>> I have a problem, I can't seem to solve.
>>
>> I'm making a class in my page that will hold the members of a FormView,
>> so I can access them freely throughout the several functions and
>> subroutines, without having to redefine them every function/subroutine.
>>
>> I ran into a problem when trying to define a GridView in that FormView
>> and I was hoping somebody can help me on this, since I'm going a tad
>> crazy. Here's part of the code:
>>
>> ---
>> Partial Public Class FM
>> Inherits System.Web.UI.Page
>>
>> Public FV_Customer As FormView
>> Public GV_PhoneNumbers As GridView =
>> FV_Customer.FindControl("GV_PhoneNumbers")
>>
>> ---
>>
>> I keep getting an "Object reference not set to an instance of an
>> object. " for the GridView. Can anybody help?
>>
>> Thanks in advance!

>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-04-2006
Perhaps the FormView is in another mode when running the FindControl
compared to what it's in when you show it? E.g Edit, Insert, ReadOnly



--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


"MRW" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hello!
>
> I have a problem, I can't seem to solve.
>
> I'm making a class in my page that will hold the members of a FormView,
> so I can access them freely throughout the several functions and
> subroutines, without having to redefine them every function/subroutine.
>
> I ran into a problem when trying to define a GridView in that FormView
> and I was hoping somebody can help me on this, since I'm going a tad
> crazy. Here's part of the code:
>
> ---
> Partial Public Class FM
> Inherits System.Web.UI.Page
>
> Public FV_Customer As FormView
> Public GV_PhoneNumbers As GridView =
> FV_Customer.FindControl("GV_PhoneNumbers")
>
> ---
>
> I keep getting an "Object reference not set to an instance of an
> object. " for the GridView. Can anybody help?
>
> Thanks in advance!
>



 
Reply With Quote
 
MRW
Guest
Posts: n/a
 
      09-04-2006
I see...

Then how do I work it so I can have all my controls and datasets
accessible by all my functions and subroutines on that page, without
having to redefine them.

For example, if I have a control, or let's go with a dataset called ds,
how can I fill it out in my onLoad, then run a subroutine that uses and
manipulates it.

Right now I have:

Partial Public Class FM
Inherits System.Web.UI.Page

Public ds As New Data.DataSet...
...
End Class

Then on every subroutine, I would have:

Sub fillout()
Dim FM As FM
FM.ds ...
End Sub

I simply want to be able to use my dataset and controls without
redefining them at every subroutine.

Thanks for any help!

Teemu Keiski wrote:
> If you have members on aspx page, and you reference them, you *never* create
> new instances of them yourself, unless you also add them to the Controls
> collection e.g create dynamical controls. If control is declared on aspx,
> page parser takes care of providing the plumbing to instantiate a control.
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
>


 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-05-2006
You pass them as arguments to the function (or take them in class
constructor) since DataSet is a reference type.

You can have the method like this (assuming static here, you could also have
instantiated class in case usage is different)

Public Class DoesSomething

Public Shared Sub fillout(dsArgument As DataSet)
'Using dsArguments
End Sub

End Class

when in the code-behind you'd just have

Partial Public Class FM
Inherits System.Web.UI.Page

Public ds As New Data.DataSet...

Protected Sub Page_Load(sender as Object, e As EventArgs)
'call the method with ds as argument
DoesSomething.fillout(ds)
End Sub

End Class


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke





"MRW" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I see...
>
> Then how do I work it so I can have all my controls and datasets
> accessible by all my functions and subroutines on that page, without
> having to redefine them.
>
> For example, if I have a control, or let's go with a dataset called ds,
> how can I fill it out in my onLoad, then run a subroutine that uses and
> manipulates it.
>
> Right now I have:
>
> Partial Public Class FM
> Inherits System.Web.UI.Page
>
> Public ds As New Data.DataSet...
> ...
> End Class
>
> Then on every subroutine, I would have:
>
> Sub fillout()
> Dim FM As FM
> FM.ds ...
> End Sub
>
> I simply want to be able to use my dataset and controls without
> redefining them at every subroutine.
>
> Thanks for any help!
>
> Teemu Keiski wrote:
>> If you have members on aspx page, and you reference them, you *never*
>> create
>> new instances of them yourself, unless you also add them to the Controls
>> collection e.g create dynamical controls. If control is declared on aspx,
>> page parser takes care of providing the plumbing to instantiate a
>> control.
>>
>> --
>> Teemu Keiski
>> ASP.NET MVP, AspInsider
>> Finland, EU
>> http://blogs.aspadvice.com/joteke
>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FindControl from C# Class Dave ASP .Net 0 02-03-2010 11:45 AM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
OnEditCommand - .FindControl Returning Null George Durzi ASP .Net 0 07-14-2003 09:54 PM



Advertisments