Solved

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

Posted on 2008-10-09
2
263 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
Comment Utility
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
Comment Utility
Can I apply this to modify an HTML element's ID and/or class?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now