473,326 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

cannot access user control properties within a webform code-behind

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
Nov 17 '05 #1
2 13708
try to declare menubar1 from code-behind before using it.
"adiel" <ad*****@hotmail.com> wrote in message
news:fe**************************@posting.google.c om...
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

Nov 17 '05 #2
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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
1
by: Rahim | last post by:
i want to change all the label control style Properties, server control properties at runtime how should i call all the label at runtime, which is present at webform, any collections???? i...
1
by: Charles A. Lackman | last post by:
Hello, I have created a User Control within Visual Studio and it contains a button that allows the user to querry a database. I dynamically add additional controls to the page based on the...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
3
by: Joe | last post by:
Hello All, I am developing a webform which creates ArrayLists of people's names and addresses (the values are retrieved from an xml file) and dynamically drops a user control onto the webform...
1
by: JoNaS | last post by:
I'm developing a server control that in turns contains another server control (i.e. Label). I instantiate the label and expose the entire Label through a property. Imports System Imports...
3
by: Mukesh | last post by:
Hi all I have to transfer a dataset and a string from a webform to a user control on the page without using viewstate or session or cookies . properties method is not working properly. if...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.