User Control Error

  • Thread starter Thread starter Arek
  • Start date Start date
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
 
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. :-)
 
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.
 
Back
Top