Solved

Accessing Site.Master in another page

Posted on 2010-11-17
3
325 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Function after success of Jquery/AJAX action 9 28
Iteration Help (Asp.net VB) 5 24
Add or delete table rows 10 53
SSRS Deployment problem 5 64
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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