User Control Handle

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to figure out how to get a reference to a user control in the page that is using that control

I have created several "Properties" within my UserControl that I want to access. Normally when I add a textbox to a form, when I go to my code behind page, the system generates all the code to instantiate that control. I can find no such code for a Usercontrol. I could instatiate it within my codebehind page, but I am guessing that if I do, that I will not get the handle on the one that the system instatiated some how

So how to I get the handle of that control

Thanks
 
Fred Walker said:
I am trying to figure out how to get a reference to a user control in the
page that is using that control.
I have created several "Properties" within my UserControl that I want to
access. Normally when I add a textbox to a form, when I go to my code
behind page, the system generates all the code to instantiate that control.
I can find no such code for a Usercontrol. I could instatiate it within my
codebehind page, but I am guessing that if I do, that I will not get the
handle on the one that the system instatiated some how.
So how to I get the handle of that control?

Well, you don't want a handle, you want a reference.

VS.NET doesn't automatically create a class member for a user control when
you place it on a page. This just means you have to add the member on your
own:

protected MyUserControl _myUserControl;

or, in VB.NET:

Protected WithEvents _myUserControl As MyUserControl

I believe this will "just work", but I'm afraid I can't take the time to
test it right now.
 
Fred Walker said:
This does not give me the reference to class member which was instatiated.
It gives me a reference to the class, but when I attempt to use it, I get
the object not set to an instance. So how do I get the reference to the
object which was created?

Ok, first of all, there's no such thing as a reference to a class, so I
don't know what you mean by that. But if you get a NullReferenceException,
then it must not be filling in the member, which surprises me. Try filling
it with FindControl.
 
Back
Top