|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to reference the masterpage body element in server codeHow do I reference the masterpage body element in ASP.NET 2.0 server code ?
I tried the following, but I get the error "hgcMasterBody is not a member of System.Web.UI.MasterPage" In the Master Page: <body id="hgcMasterBody" runat="server"> ..... </body> In the ASPX page: <%@ MasterType virtualpath="MyMasterPage.master" %> ..... <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" End Sub </script> I added a @ MasterType directive to the ASPX page:
<%@ MasterType VirtualPath="~/MasterPage.master" %> and now I get the error: Compiler Error Message: BC30390: 'ASP.masterpage_master.Protected Dim WithEvents hgcMasterBody As System.Web.UI.HtmlControls.HtmlGenericControl' is not accessible in this context because it is 'Protected'. Any help would be greatly appreciated. --------------------------------------- Show quoteHide quote "Roberto Kohler" <rkoh***@intranetslab.com> wrote in message news:eIeF6pMBGHA.344@TK2MSFTNGP11.phx.gbl... > How do I reference the masterpage body element in ASP.NET 2.0 server code > ? > > I tried the following, but I get the error "hgcMasterBody is not a member > of System.Web.UI.MasterPage" > > In the Master Page: > <body id="hgcMasterBody" runat="server"> > .... > </body> > > In the ASPX page: > <%@ MasterType virtualpath="MyMasterPage.master" %> > .... > <script runat="server"> > Protected Sub Page_Load(ByVal sender As Object, ByVal e As > System.EventArgs) > Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" > End Sub > </script> > > Hi Roberto,
I have just created a simple master page with the following code in it and it works just fine: <body onkeydown="catchKeyPress(window.event.keyCode, window.event.srcElement);"> Here is the link to the test page: http://www.webswapp.com/CodeSamples/aspnet20/test1.aspx Show quoteHide quote "Roberto Kohler" wrote: > I added a @ MasterType directive to the ASPX page: > <%@ MasterType VirtualPath="~/MasterPage.master" %> > > and now I get the error: > Compiler Error Message: BC30390: 'ASP.masterpage_master.Protected Dim > WithEvents hgcMasterBody As System.Web.UI.HtmlControls.HtmlGenericControl' > is not accessible in this context because it is 'Protected'. > > Any help would be greatly appreciated. > > --------------------------------------- > "Roberto Kohler" <rkoh***@intranetslab.com> wrote in message > news:eIeF6pMBGHA.344@TK2MSFTNGP11.phx.gbl... > > How do I reference the masterpage body element in ASP.NET 2.0 server code > > ? > > > > I tried the following, but I get the error "hgcMasterBody is not a member > > of System.Web.UI.MasterPage" > > > > In the Master Page: > > <body id="hgcMasterBody" runat="server"> > > .... > > </body> > > > > In the ASPX page: > > <%@ MasterType virtualpath="MyMasterPage.master" %> > > .... > > <script runat="server"> > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As > > System.EventArgs) > > Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" > > End Sub > > </script> > > > > > > > Hi Phillip,
Thanks for replying. Your solution works fine if all the aspx pages that use that master-page want to use the same event handler. The problem that I am trying to solve is how to set the body onkeydown event handler from an aspx file that uses the master-page. That is why I'm trying to figure out how to reference the masterpage body element from another aspx file. For example, I could choose to set the onkeydown event handler to null from some pages, and to catchKeyPress() from other pages. Another example is, if for some strange reason I would need to set the body background color to one color from some aspx pages and to a different color from other aspx pages. Roberto Show quoteHide quote "Phillip Williams" <Phillip.Willi***@webswapp.com> wrote in message news:EDD21686-8876-4858-A472-63D217A09E88@microsoft.com... > Hi Roberto, > > I have just created a simple master page with the following code in it and > it works just fine: > <body onkeydown="catchKeyPress(window.event.keyCode, > window.event.srcElement);"> > > Here is the link to the test page: > http://www.webswapp.com/CodeSamples/aspnet20/test1.aspx > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Roberto Kohler" wrote: > >> I added a @ MasterType directive to the ASPX page: >> <%@ MasterType VirtualPath="~/MasterPage.master" %> >> >> and now I get the error: >> Compiler Error Message: BC30390: 'ASP.masterpage_master.Protected Dim >> WithEvents hgcMasterBody As >> System.Web.UI.HtmlControls.HtmlGenericControl' >> is not accessible in this context because it is 'Protected'. >> >> Any help would be greatly appreciated. >> >> --------------------------------------- >> "Roberto Kohler" <rkoh***@intranetslab.com> wrote in message >> news:eIeF6pMBGHA.344@TK2MSFTNGP11.phx.gbl... >> > How do I reference the masterpage body element in ASP.NET 2.0 server >> > code >> > ? >> > >> > I tried the following, but I get the error "hgcMasterBody is not a >> > member >> > of System.Web.UI.MasterPage" >> > >> > In the Master Page: >> > <body id="hgcMasterBody" runat="server"> >> > .... >> > </body> >> > >> > In the ASPX page: >> > <%@ MasterType virtualpath="MyMasterPage.master" %> >> > .... >> > <script runat="server"> >> > Protected Sub Page_Load(ByVal sender As Object, ByVal e As >> > System.EventArgs) >> > Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" >> > End Sub >> > </script> >> > >> > >> >> >> Ok, I got you. I modified the sample with a new link to another sample to
demonstrate how to access a control on a master page from the content page: http://www.webswapp.com/CodeSamples/aspnet20/test2.aspx Show quoteHide quote "Roberto Kohler" wrote: > Hi Phillip, > > Thanks for replying. > > Your solution works fine if all the aspx pages that use that master-page > want to use the same event handler. > > The problem that I am trying to solve is how to set the body onkeydown event > handler from an aspx file that uses the master-page. That is why I'm trying > to figure out how to reference the masterpage body element from another aspx > file. > > For example, I could choose to set the onkeydown event handler to null from > some pages, and to catchKeyPress() from other pages. Another example is, if > for some strange reason I would need to set the body background color to one > color from some aspx pages and to a different color from other aspx pages. > > Roberto > > > "Phillip Williams" <Phillip.Willi***@webswapp.com> wrote in message > news:EDD21686-8876-4858-A472-63D217A09E88@microsoft.com... > > Hi Roberto, > > > > I have just created a simple master page with the following code in it and > > it works just fine: > > <body onkeydown="catchKeyPress(window.event.keyCode, > > window.event.srcElement);"> > > > > Here is the link to the test page: > > http://www.webswapp.com/CodeSamples/aspnet20/test1.aspx > > -- > > HTH, > > Phillip Williams > > http://www.societopia.net > > http://www.webswapp.com > > > > > > "Roberto Kohler" wrote: > > > >> I added a @ MasterType directive to the ASPX page: > >> <%@ MasterType VirtualPath="~/MasterPage.master" %> > >> > >> and now I get the error: > >> Compiler Error Message: BC30390: 'ASP.masterpage_master.Protected Dim > >> WithEvents hgcMasterBody As > >> System.Web.UI.HtmlControls.HtmlGenericControl' > >> is not accessible in this context because it is 'Protected'. > >> > >> Any help would be greatly appreciated. > >> > >> --------------------------------------- > >> "Roberto Kohler" <rkoh***@intranetslab.com> wrote in message > >> news:eIeF6pMBGHA.344@TK2MSFTNGP11.phx.gbl... > >> > How do I reference the masterpage body element in ASP.NET 2.0 server > >> > code > >> > ? > >> > > >> > I tried the following, but I get the error "hgcMasterBody is not a > >> > member > >> > of System.Web.UI.MasterPage" > >> > > >> > In the Master Page: > >> > <body id="hgcMasterBody" runat="server"> > >> > .... > >> > </body> > >> > > >> > In the ASPX page: > >> > <%@ MasterType virtualpath="MyMasterPage.master" %> > >> > .... > >> > <script runat="server"> > >> > Protected Sub Page_Load(ByVal sender As Object, ByVal e As > >> > System.EventArgs) > >> > Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" > >> > End Sub > >> > </script> > >> > > >> > > >> > >> > >> > > >
Wizard Control - Referencing buttons in <StepNavigationTemplate>
Datagrid only shows the header masterpages: body event handler <customErrors mode="Off"/> ERROR Walking thr DataReader Repeater.Itemcommand not firing Can RDLC Reports be used with Oracle data sources? Membership roles question Textbox Select Text I don't get it...Crystal Reports |
|||||||||||||||||||||||