Struggling With Concept

Discussion in 'ASP .Net' started by One Handed Man \( OHM#\), Jun 12, 2004.

  1. Hi Folks,
    As you may know I'm new to ASP.NET and Im having trouble
    grappling with one concept.

    If I create a user control and place it on a page I can access its public
    properties through a pre-render block, But I cant access its public
    properties via code. In say the Page_Load event.

    Surely if the control is registered, when the Page_Load Loads, it must have
    access to the UserControl Object otherwise whats the point?

    Please tell me where Im going wrong !

    Cheers
     
    One Handed Man \( OHM#\), Jun 12, 2004
    #1
    1. Advertising

  2. One Handed Man \( OHM#\)

    Jared Guest

    You can also declare the control at the module level and use the withevents
    keyword to expose its events if they are needed. Then you can reference the
    control via the code editor.

    #Region " Web Form Designer Generated Code "
    'Instantiate the control here and you can use it throughout the page by
    name.
    Protected WithEvents MyUserControl As New MyUserControl

    'NOTE: The following placeholder declaration is required by the Web Form
    Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not IsPostBack Then
    With Me.MyUserControl
    .DataSource = SomeDataSource
    .Text = "SomeValue"
    .SomeOtherProperty = "SomeOtherValue"
    End With
    End If
    End Sub

    "One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
    news:...
    > Hi Folks,
    > As you may know I'm new to ASP.NET and Im having trouble
    > grappling with one concept.
    >
    > If I create a user control and place it on a page I can access its public
    > properties through a pre-render block, But I cant access its public
    > properties via code. In say the Page_Load event.
    >
    > Surely if the control is registered, when the Page_Load Loads, it must
    > have
    > access to the UserControl Object otherwise whats the point?
    >
    > Please tell me where Im going wrong !
    >
    > Cheers
    >
    >
     
    Jared, Jun 12, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin
    Replies:
    6
    Views:
    674
    Martin
    Dec 29, 2003
  2. Guest
    Replies:
    5
    Views:
    399
    Guest
    Dec 26, 2004
  3. John
    Replies:
    1
    Views:
    405
    =?Utf-8?B?RWx0b24gVw==?=
    Oct 20, 2005
  4. Karl Seguin
    Replies:
    0
    Views:
    409
    Karl Seguin
    Dec 8, 2005
  5. George
    Replies:
    4
    Views:
    294
    John Hazen
    Sep 27, 2005
Loading...

Share This Page