Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding attribute to body tag in masterpage

Status
Not open for further replies.

AndyH1

Programmer
Jan 11, 2004
350
GB
I'm trying to add two tags to the body tag into a masterpage to give
<body onbeforeunload="javascript:wait.style.visibility" = 'visible';" onunload="javascript:wait.style.visibility">

from the content page in certain pages. It seems possible and is discussed here:

However I think this is in C# and I only know VB so the bit

using System.Web.UI.HtmlControls;
public partial class MyMasterPage : System.Web.UI.MasterPage
{
public HtmlGenericControl BodyTag
{
get
{
return MasterPageBodyTag;
}
set
{
MasterPageBodyTag = value;
}
}

is confusing me, I'm not sure of the syntax or where to put it in the code behind page, which contains

Partial Class Reports
Inherits System.Web.UI.MasterPage
End Class

and I haven't been able to get it to work. Can anyone advise me, or point me to a similar reference in VB or a better way of doing this in VB?
Thanks
Andy
 
The article tells you to do this in your content page's code behind:

Code:
protected void Page_Load(object sender, EventArgs e)
{
    Master.BodyTag.Attributes.Add("onload", "SayHello()");
...

There are plenty of tools on line that will convert between C# and VB
 
Thanks, but in my masterpage (called Reports.master) I have done what I thought was the conversion:

Imports System.Web.UI.HtmlControls
Partial Class Reports
Inherits System.Web.UI.MasterPage

Public Property BodyTag() As HtmlGenericControl
Get
Return MasterPageBodyTag
End Get
Set(ByVal value As HtmlGenericControl)
MasterPageBodyTag = value
End Set
End Property
End Class

but when I use it

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Master.BodyTag.Attributes.Add("onload", "SayHello()");
End Sub

in the content page I get the master.Bodytag underlined with the error 'BodyTag is not a member of System.Web.UI.MasterPage'. Not sure what I'm doing wrong

Andy

 
Sorry my mistake forgot the
<%@ MasterType TypeName="MyMasterPage" %>
All works now thanks
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top