Good afternoon.

I am using MS Visual Web Developer 2010 Express with VB.Net.

I have 3 web pages - Site.Master with Site.Master.vb, Login.aspx with Login.aspx.vb, CreateAccount.aspx with CreateAccount.aspx.vb

If I put the following statement in the Site.Master.vb Page_Load: NavigationMenu.Items.Item(2).Selectable = False it works fine. It makes the menu item unselectable. However, this is not where I want to do this.

I want to be able to make the menu items selectable/unselectable programatically thru other programs such as Login.aspx.vb and CreateAccount.aspx.vb. I realize that NavigationMenu is declared in Site.Master and not declared in Login.aspx.vb or CreateAccount.aspx.vb

How can I get this to work in Login.aspx.vb and CreateAccount.aspx.vb?

I tried to include sample code but I got: The code snippet in your post is formatted incorrectly. Please use the Code button in the editor toolbar when posting whitespace-sensitive text or curly braces

Thank you for your time.


Recommended Answers

Even if the control is on the master page, you can access it via pages that reference the master page.

See this MSDN article:

You can also expose controls by creating public properties as described in this other article:

Jump to Post

All 4 Replies

Thank you JorgeM. But, I don't get it. I read the articles and tried various things but I'm no closer than I was.

I'm including the code that I couldn't get to post the first time. All I want to do is access the NavigationMenu items and change their property values.

Thanks again.

Figure 1: Site.Master.aspx

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb" Inherits="SunriseFarms.Site" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en">
<head id="Head1" runat="server">
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    <style type="text/css">
            font-size: medium;
    <form id="Form1" runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                    Sunrise Farms <span class="style1">Homeowner&#39;s Association</span></h1>

            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home" Selected="True"/>
                        <asp:MenuItem NavigateUrl="SFDR.pdf" Text="Declaration of Restrictions" 
                            Value="Declaration of Restrictions"></asp:MenuItem>
                        <asp:MenuItem NavigateUrl="~/HOADues.aspx" Text="HOA Dues" Enabled="True"/>
                        <asp:MenuItem NavigateUrl="" Text="Violations">
                            <asp:MenuItem Text="Report A Violation" Value="Report A Violation">
                            <asp:MenuItem Text="View Violations" Value="View Violations">
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        <div class="clear">
    <div class="footer">



Figure 2: Site.Master.vb

Public Class Site
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        NavigationMenu.Items.Item(2).Selectable = False     

    End Sub

End Class

Figure 3: Login.aspx

<%@ Page Title="Log In" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Login.aspx.vb" Inherits="SunriseFarms.Login" %>

Figure 4: Login.aspx.vb

Public Class Login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        NavigationMenu.Items.Item(2).Selectable = False

''''''''''''''It doesn't like the above statement
    End Sub

Remove the code from your master page's code behind.

On the code behind for your login.aspx page, use the following:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim navMenu As Menu
        navMenu = CType(Master.FindControl("NavigationMenu"), Menu)
        navMenu.Items.Item(2).Selectable = False

    End Sub

JorgeM. Fantastic! It works great!

Thank you so much!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.