Solved

How do I access a shared property on a MasterPage on other pages?

Posted on 2008-10-09
2
265 Views
Last Modified: 2008-10-21
I have a web site that I am developing that uses a MasterPage.  On my layout I have a navigation bar that highlights the the current page, as long as the page's link on the bar has an id of "current".  My aim is to have a programmatic solution to set the appropriate link's id to current when changing pages.  I got a suggestion to do a property on the MasterPage, but I can only access it on my MasterPage's  backend.  Code snippet has the section on the MasterPage I am referring to, as well as its backend and a content page.
//MasterPage Backend
 
Partial Class MasterPage
    Inherits System.Web.UI.MasterPage
    Public Property PageSection() As String
        Get
            Return String.Format("id={0}", Chr(34) & "current" & Chr(34))
        End Get
        Set(ByVal value As String)
 
        End Set
    End Property
 
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.PageSection = "home"
 
    End Sub
End Class
 
//MasterPage Frontend
<div id="nav_main">
  <ul>
    <li id="nav_home"><a href="default.aspx">Home</a></li>
    <li id="nav_faq"><a href="faq.aspx">FAQ</a></li>
    <li id="nav_vid"><a href="#">Videos</a></li>
    <li id="nav_ph1"><a href="#">Button 4</a></li>
    <li id="nav_ph2"><a href="#">Button 5</a></li>
  </ul>
</div>
 
//content
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="faq.aspx.vb" Inherits="faq" title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>

Open in new window

0
Comment
Question by:Anders-Leet
2 Comments
 
LVL 15

Assisted Solution

by:Solar_Flare
Solar_Flare earned 50 total points
ID: 22681679
you can cast the pages .Master property to access controls on the master page


eg

TextBox t = ((MyProject.MyMasterPage)this.Master).TextBox1;
t.Text = "new value";
0
 

Accepted Solution

by:
Anders-Leet earned 0 total points
ID: 22681736
Can I apply this to modify an HTML element's ID and/or class?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question