Home All Groups Group Topic Archive Search About
Author
4 Sep 2006 6:46 PM
MRW
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!

Author
4 Sep 2006 7:05 PM
RHIZOME
Declare new with Public FV_Customer As FormView

e.g. Public FV_Customer As New FormView



MRW wrote:
Show quote
> 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!
Author
4 Sep 2006 7:12 PM
MRW
What the???

Mmm...

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

Thanks for the help!

RHIZOME wrote:
Show quote
> 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!
Author
4 Sep 2006 7:21 PM
Teemu Keiski
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


Show quote
"RHIZOME" <jhol***@networklogistic.com> wrote in message
news:1157396700.837173.98240@h48g2000cwc.googlegroups.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!
>
Author
4 Sep 2006 7:33 PM
MRW
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:
Show quote
> 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
>
>
Author
5 Sep 2006 3:41 PM
Teemu Keiski
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





Show quote
"MRW" <mwin***@yahoo.com> wrote in message
news:1157398392.091032.219590@p79g2000cwp.googlegroups.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
>>
>>
>
Author
4 Sep 2006 7:23 PM
Teemu Keiski
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


Show quote
"MRW" <mwin***@yahoo.com> wrote in message
news:1157395605.826964.118540@e3g2000cwe.googlegroups.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!
>

AddThis Social Bookmark Button