I discovered the answer to my own question. You just need to add a member
to your page behind class with the same name as the ID of the UserControl
and with a type of your UserControl, which is usually the same as the first
part of the UserControl's ascx file name. For example, if your UserControl
is defined in Foo.ascx and you place it in Bar.aspx as:
<uc1:Foo id="Foo1" runat="server"></uc1:Foo>
then in your code-behind page for Bar.aspx you just need to have:
Public Class Bar
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
...
' This must be put in manually, even though it ought to be done
automatically
' by VS.NET when you put the user control on the page, just like it
did for
' the button above
Protected Foo1 As Foo
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As
System.EventArgs) Handles Button1.Click
Foo1.MyProperty = "Whatever"
End Sub
...
End Class
and then you can refer to the properties, etc. of the UserControl.
Not my comment above that I think that it's a bug that VS.NET doesn't
automatically put the member variable in there for you the way it does for
other server controls.
-Mark
"Mark Friedman" <bi******@yahoo.com> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
I can't seem to figure out how to get a reference to a UserControl in the
code-behind for the page that contains the control. All the examples I've
seen show how to pass property values from the containing page's HTML to
the UserControl but nothing I've seen shows how to reference the UserControl's
properties (or subcontrols) from the containing page's server-side code.
Note that I'm not creating the UserControl prgrammatically via
LoadControl - I'm creating the UserControl declaratively in the page's HTML.
Thanks in advance for any help.
-Mark