User Control Error

A

Arek

Hey,

I have a user control that I want to use as a header in my application
on different pages.
So I follow the example first from one book but it doesn't work, then
from second book...etc since quite a few hours already.
My user control is very simple, has label1 and property:
Public Property Lab() As String
Get
Return label1.Text
End Get
Set(ByVal Value As String)
label1.Text = Value
End Set
End Property

Then I added it to the page where I wanted to use it. When I try to run
my page I get an error:

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:


Line 22:
Line 23: Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Line 24: headercontracts1.napis1 = "Text"
Line 25: End Sub

I have no idea what can be wrong.
Regards
Arek
 
J

Josh

Sometimes if you write the user control into the HTML manually, the code
behind page will not be updated, i.e. the declaration for your user control
will not exist, therefore the name does not exist.

p.s. Switch C#, it's nice, its cudderly yet grown up. :)
 
A

Arek

Solution was very simple.
In HTML I needed to change ID of the user control for the one that I was
using when I was declaring the control on the page.
e.g.
Protected AA as AAControl, then in HTML id of the control has to be AA.
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top