problems with referencing control from master page on content page

  • Thread starter Michael Richter
  • Start date
M

Michael Richter

hi, all,

I'm a desperately seeking (MS search, google ...) for a solution in
referencing a menu control that is placed on a master page from a content
page.
Let me show you what I have got (VS 2005, VB.NET only):
* MasterPage:
1 <asp:Menu ID="KostenMenu" Enabled="true" EnableViewState="true"
runat="server" Orientation="Vertical" Visible="False"
DynamicEnableDefaultPopOutImage="False"
StaticEnableDefaultPopOutImage="False" CssClass="Menu">
2 <Items> ... </Items>
3 </asp:Menu>
[...]
10 <asp:ContentPlaceHolder ID="ContentPlaceHolderPSP" runat="server">
11 </asp:ContentPlaceHolder>
--- end master page ---

* Content Page:
* aspx file:
1 <%@ Page Language="VB" MasterPageFile="~/MasterPSP.master"
AutoEventWireup="false"
CodeFile="[FileName].aspx.vb" Inherits="[Name of aspx file]"
Title="[...]" %>
2 <%@ MasterType VirtualPath="~/MasterPSP.master" %>
[...]

* aspx.vb file (code behind/beside):
1 Private Sub InitializePage()
2 'delegate from master
3 Dim KostenMenuA As Menu
4 Dim KostenMenu_ItemClick As EventHandler
5 KostenMenuA = New Master.FindControl("KostenMenu")
6 AddHandler KostenMenu_ItemClick, New KostenMenuA.MenuItemClick()
[...]
10 End Sub
[...]
100 Protected Sub KostenMenu_ItemClicked(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.MenuEventArgs) Handles KostenMenu_ItemClick()
[things to do]
110 End Sub
--- end content page ---

As you might have experienced once Visual Studio claims "Type
'Master.FindControl' is not defined" in line 5 of aspx.vb file. which I
cannot understand really. (Perhaps I'm just hung up in the circle of my on
thinking about that problem). All samples I found on the net make use of the
above syntax and seem working but not on my system :-(( .
Ok, if one has a heart for a .Net newbie like me, please help.
Thanks in advance,

michael
 
M

Michael Richter

addendum:

I just solved the first part of my problem in the aspx.vb file:

5 KostenMenuA = New Master.FindControl("KostenMenu")

should be

5 KostenMenuA = New Master.Parent.FindControl("KostenMenu")


:)
this is as I found out because the master pages naming container is
System.Web.UI.Control and the menu's naming container is
System.Web.UI.WebControls. FindControl does only search immediate or top
level naming containers of the referenced object.

still

6 AddHandler KostenMenu_ItemClick, New KostenMenuA.MenuItemClick()

does not work at all. Visual Studio says "Type
'KostenMenuA.MenuItemClick' is not defined" ...
I am feeling very unhappy about that ...

michael
 
M

Michael Richter

uh-ah, got more
Dim *WithEvents* KostenMenuA As Menu
[...]
KostenMenuA = CType(Master.Parent.FindControl("KostenMenu"), Menu)
[...]
Protected Sub KostenMenu_ItemClicked(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.MenuEventArgs) Handles KostenMenuA.MenuItemClick
[...]
End Sub

.... and no errors by VS2005 anymore.

give me suggestions whether this is best breed ...

thx

michael
 
M

Michael Richter

I am totally confused ... today I can leave out .master and no errors appear
in VS2005 and code is working fine ... what the heck is going on here? do
classes move around their hierarchies?

michael
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top