0

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.

tfj

Edited by JorgeM: fixed formatting

2
Contributors
4
Replies
27
Views
3 Years
Discussion Span
Last Post by tfj
0

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.
tfj

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
    <style type="text/css">
        .style1
        {
            font-size: medium;
        }
    </style>
</head>
<body>
    <form id="Form1" runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                <h1>
                    Sunrise Farms <span class="style1">Homeowner&#39;s Association</span></h1>
            </div>

            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <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>
                            <asp:MenuItem Text="View Violations" Value="View Violations">
                            </asp:MenuItem>
                        </asp:MenuItem>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
                    </Items>
                </asp:Menu>
            </div>
        </div>
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="footer">

        2014 

    </div>
    </form>
</body>
</html>

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

Edited by JorgeM: Fixed formatting.

0

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
0

JorgeM. Fantastic! It works great!

Thank you so much!

tfj

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.