cannot access user control properties within a webform code-behind

Discussion in 'ASP .Net' started by adiel, Jul 1, 2003.

  1. adiel

    adiel Guest

    Hello, I am trying to access the properties and methods from a user
    control within the code-behind file for a webform but I am receiving
    the message:

    Name 'MenuBar1' is not declared

    It does not recognize the user control in the code behind...
    Here is the code for the user control:

    MenuBar.ascx:
    <%@ Control Language="vb" AutoEventWireup="false"
    Codebehind="MenuBar.ascx.vb" Inherits="TestApp.MenuBar"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

    ....

    MenuBar.ascx.vb:
    Public MustInherit Class MenuBar
    Inherits System.Web.UI.UserControl

    Dim x As String

    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
    End Sub

    Public Property testX() As String
    Get
    testX = x
    End Get
    Set(ByVal Value As String)
    x = Value
    End Set
    End Property
    End Class

    This is the page that is using the code:

    test.aspx:
    <%@ Register TagPrefix="uc1" TagName="MenuBar" Src="MenuBar.ascx" %>
    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="test.aspx.vb" Inherits="TestApp.test"%>

    ....
    <uc1:menubar id="MenuBar1" runat="server"></uc1:menubar>

    Then in my code behind:
    test.aspx.vb

    Dim y As String
    y = MenuBar1.testX()

    I receive the message:
    Name 'MenuBar1' is not declared

    ....and MenuBar1 has the blue squiggly line....

    I know the problem is that it does not understand what 'MenuBar1' is,
    my question is, what am I missing so that i can get the code behind to
    recognize 'MenuBar1'...

    Thanks Before Hand,
    Adiel
     
    adiel, Jul 1, 2003
    #1
    1. Advertising

  2. adiel

    zPaul Guest

    try to declare menubar1 from code-behind before using it.


    "adiel" <> wrote in message
    news:...
    > Hello, I am trying to access the properties and methods from a user
    > control within the code-behind file for a webform but I am receiving
    > the message:
    >
    > Name 'MenuBar1' is not declared
    >
    > It does not recognize the user control in the code behind...
    > Here is the code for the user control:
    >
    > MenuBar.ascx:
    > <%@ Control Language="vb" AutoEventWireup="false"
    > Codebehind="MenuBar.ascx.vb" Inherits="TestApp.MenuBar"
    > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    >
    > ...
    >
    > MenuBar.ascx.vb:
    > Public MustInherit Class MenuBar
    > Inherits System.Web.UI.UserControl
    >
    > Dim x As String
    >
    > 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
    > End Sub
    >
    > Public Property testX() As String
    > Get
    > testX = x
    > End Get
    > Set(ByVal Value As String)
    > x = Value
    > End Set
    > End Property
    > End Class
    >
    > This is the page that is using the code:
    >
    > test.aspx:
    > <%@ Register TagPrefix="uc1" TagName="MenuBar" Src="MenuBar.ascx" %>
    > <%@ Page Language="vb" AutoEventWireup="false"
    > Codebehind="test.aspx.vb" Inherits="TestApp.test"%>
    >
    > ...
    > <uc1:menubar id="MenuBar1" runat="server"></uc1:menubar>
    >
    > Then in my code behind:
    > test.aspx.vb
    >
    > Dim y As String
    > y = MenuBar1.testX()
    >
    > I receive the message:
    > Name 'MenuBar1' is not declared
    >
    > ...and MenuBar1 has the blue squiggly line....
    >
    > I know the problem is that it does not understand what 'MenuBar1' is,
    > my question is, what am I missing so that i can get the code behind to
    > recognize 'MenuBar1'...
    >
    > Thanks Before Hand,
    > Adiel
     
    zPaul, Jul 1, 2003
    #2
    1. Advertising

  3. adiel

    adiel Guest

    Thanks zPaul, I have two questions concerning that suggestion:

    1. Do you have a sample code on how I would declare this user control?
    2. If I declare it from code behind (test.aspx.vb), how would .NET
    know that this is the same control being used in the webform
    (test.aspx)?

    Thanks again,
    Adiel Gonzalez

    > try to declare menubar1 from code-behind before using it.
     
    adiel, Jul 2, 2003
    #3
    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. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    594
    Alphonse Giambrone
    Jun 28, 2003
  2. titof
    Replies:
    0
    Views:
    517
    titof
    Jul 24, 2003
  3. CW
    Replies:
    3
    Views:
    6,155
    John Sivilla
    May 2, 2004
  4. Earl Teigrob
    Replies:
    2
    Views:
    451
    Earl Teigrob
    Jun 8, 2004
  5. Jon Ratcliffe

    Accessing User Control properties from C# Code Behind...

    Jon Ratcliffe, Apr 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    1,223
    Jon Ratcliffe
    Apr 23, 2004
Loading...

Share This Page