Repeater control in a web user control

  • Thread starter Thread starter bill
  • Start date Start date
B

bill

I have a Repeater control in a web user control.

The web user control has a public method named PopulateRepeater which takes
an ID as an parameter and populates the repeater control based on the
parameter.

When I call PopulateRepeater from the User Control page_load event it
populates the repeater without a problem.

When I call PopulateRepeater from a procedure in the web form which contains
the user control, I get an error in PopulateReader (which is in the User
Control code behind module):

Sub PopulateRepeater (iID as integer)
dim ds as DataSet = GetDataSet(iID)
Repeater1.DataSource = ds ' causes error "Object reference not set
to an instance of an object"
Repeater1.DataBind
Exit Sub
 
Apparently, the method called is not returning a DataSet.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
It's not the dataset, its the Repeater which is 'nothing'.

I found the reason - the way a web user control is declared is different in
VS2005 than VS2003, I guess because of the partial class structure of the
web forms..

In VS2005, I find you just go ahead and call the user control directly using
its ID -- without creating an object variable--in order to call it's methods
from the host code behind:
ucUserControl1.PopulateRepeater

In VS 2003, the user control first had to be declared in the host code
behind in order to call its methods:
Protected ucUserControl1 as New ucUserControl

If you do this in VS2005, you get an error
"ucUserControl1 already declared as... in this class"
so I was using
dim ucUserControl1 as new ucUserControl
and getting the "Object reference not set to an instance of an object"
error.

I'm still getting used to partial classes.
 
Glad you got it sorted out!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Thanks!

Kevin Spencer said:
Glad you got it sorted out!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top