473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

FindControl in Class

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!

Sep 4 '06 #1
6 1693
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!
Sep 4 '06 #2
MRW
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!
Sep 4 '06 #3
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" <jh*****@networklogistic.comwrote in message
news:11*********************@h48g2000cwc.googlegro 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!

Sep 4 '06 #4
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" <mw*****@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro 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!

Sep 4 '06 #5
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:
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

Sep 4 '06 #6
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" <mw*****@yahoo.comwrote in message
news:11**********************@p79g2000cwp.googlegr 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


Sep 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Harry F. Harrison | last post by:
Here's the situation...Context - Using an Inherited WebControl object as a base for server custom controls. In a web custom control, whenever I create a child control and add it to the Controls...
2
by: encoad | last post by:
Hi everyone, I'm slowly going mad with Masterpages and the FindControl. After a couple days of figuring out how to use the FindControl command from within a Masterpage, I still can't explain...
0
by: David Rees | last post by:
Before I was using LoadControl and a slew of User Controls to achive the same effect, but I realised a custom TemplatedControl was the better way of doing it. Anyway, this is the templated...
0
by: tshad | last post by:
I have a .ascx file that I converted to a class. But I am getting the following error: error BC30469: Reference to a non-shared member requires an object reference. The error is for the...
3
by: tshad | last post by:
I have a .ascx file that I converted to a class. But I am getting the following error: error BC30469: Reference to a non-shared member requires an object reference. The error is for the...
4
by: Jim McGivney | last post by:
I am trying to form a string by concatenating the Text strings of a number of Label controls. The Labels are Label33 to Label64. I thought I would use a For Loop to increment through the labels. ...
14
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from...
15
by: | last post by:
I dynamically create controls (textboxes) in a repeater control. I know their names (eg. TextBox1). How do I find the text of TextBox1 in the Form? FindControl does not seem to work.
7
by: AAaron123 | last post by:
Me.FindControl("MissionScheduleID"), below returns null. Do you know what I'm doing wrong? Thanks ***In my .aspx file I have: asp:Content ID="Content3"...
1
by: ptcoder | last post by:
Hello everyone. I have done a lot of reading regarding the recursive issue with FindControl. I have a FormView with an <EditItemTemplate> and all I want to do is add javascript attributes to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.