problems with referencing control from master page on content page

Discussion in 'ASP .Net Web Controls' started by Michael Richter, Jan 9, 2006.

  1. 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
     
    Michael Richter, Jan 9, 2006
    #1
    1. Advertising

  2. 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
     
    Michael Richter, Jan 9, 2006
    #2
    1. Advertising

  3. uh-ah, got more news:

    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
     
    Michael Richter, Jan 9, 2006
    #3
  4. 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
     
    Michael Richter, Jan 10, 2006
    #4
    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. PJ
    Replies:
    3
    Views:
    604
    Christopher Reed
    Jan 4, 2006
  2. Doug McCann
    Replies:
    1
    Views:
    1,134
    William Brogden
    Aug 5, 2004
  3. Replies:
    0
    Views:
    757
  4. Rolf Welskes
    Replies:
    7
    Views:
    1,013
    Steven Cheng[MSFT]
    Aug 22, 2006
  5. Replies:
    0
    Views:
    115
Loading...

Share This Page