User control newbie question - pls help

P

Paul Barnett

I have a user control with a label and a method. The webform should call
the method on the user control and populate the label. I am getting
object not set errors as soon as I try to access the label on the user
control.

A small sample of code would be greatly appreciated.
 
T

Travis Bolton

Nice little "secret" solution to this I believe.

You need to explicitly declare the object variable for your user control,
unlike when you add a normal control and VS does it for you:

Protected WithEvents Control ID As UsercontrolType (where Control ID is the
id of the control after you dragged it onto your web form, and
usercontroltype is the class name)

Hope this helps. Not sure if the WithEvents is required or recommend, might
depend on your implementation
 
V

Victor Garcia Aprea [MVP]

Small note: keep in mind that for the parser to do its magic, you need to
name your member variable *exactly* after the value of the ID attribute
given in your usercontrol tag.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top