Solved

Accessing Site.Master in another page

Posted on 2010-11-17
3
317 Views
Last Modified: 2012-05-10
Good afternoon,
Ive got my <body> tag setup in my site.master file, and I want to be able to set an attribute of the body in a WebForm.

I thought I could just try and set the page in site.master like '<body id="divBody" runat="server">', and then in my PageLoad on the webform I want to set it on do:-
Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        divBody.Attributes.Add("oncontextmenu", "return false"))
    End Sub
End Class

But this doesnt work.

Any ideas how I can set the Body attributes in a different form?

Thank you
0
Comment
Question by:tonelm54
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 34155234
In principal you can do:
Dim master As YourMasterPage = CType(Me.Master, YourMasterPage)
master.divBody.Attributes.Add("oncontextmenu", "return false")

Open in new window

Although the body tag is probably protected by default. So, you can either increase its scope to Public, or add a property to the master page to expose it.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34155255
If you wanted to you could add a MasterType directive to your page and then you wouldn't need to do the CType either.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 34158900
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

19 Experts available now in Live!

Get 1:1 Help Now