That is because the .aspx is turned into a class that actually inherits from
the class in your .vb file. The .aspx contains the declaration of your
control. The name you give it there, needs to match up to a variable in the
class. Now, if this variable is declared as private, the .aspx class cannot
see it - and thus there is a disconnect there, and the object does not get
instantiated. If it is protected, the then .aspx class can see it (because
it inherits from the .vb class), and it is matched up to the object declared
in the .aspx itself.
"Nad" <Na*@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
Hello,
When I add a User Control to a web form and then try to declare it in the
code as a private member it doesn't get instantiated. However with
'protected' it's OK!
For example I get a runtime error on the line indicated in
InitializeComponent() because the user control is null. However if I
declare
it as 'protected' it's ok.
private myUserControl userControl;
...
InitializeComponent()
{
...
userControl.Click += new EventHandler(userControl_Click);
}