|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
masterpages: body event handlerI am trying to add a body event handler to a page that uses a masterpage.
I need to do something like: <body onkeydown="catchKeyPress(window.event.keyCode, window.event.srcElement);"> The problem is that when the page uses a masterpage, I can't add a <body> tag. How do I set a body event handler when a page uses masterpages ? You would add the body with the onkeydown attribute to the master page.
Now, if you only want this on some pages, you can try this: In the master page: <body id="hgcMasterBody" runat="server"> ..... </body> In the ASPX page: <%@ MasterType virtualpath="MyMasterPage.master" %> ..... <script runat="server"> Master.hgcMasterBody.Attributes["onkeydown"] = "catchKeyPress(window.event.keyCode, window.event.srcElement);"; ...... </script> ..... I haven't tried this myself, so you may have to tweak it a bit. -- Show quoteHide quoteChristopher A. Reed "The oxen are slow, but the earth is patient." "Roberto Kohler" <rkoh***@intranetslab.com> wrote in message news:%23NBQEHKBGHA.1312@TK2MSFTNGP09.phx.gbl... >I am trying to add a body event handler to a page that uses a masterpage. > I need to do something like: > > <body onkeydown="catchKeyPress(window.event.keyCode, > window.event.srcElement);"> > > The problem is that when the page uses a masterpage, I can't add a <body> > tag. > How do I set a body event handler when a page uses masterpages ? > > Christopher,
Thanks for your response. I can't figure out how to reference the masterpage body element in ASP.NET 2.0 server code. As per your suggestion, I tried <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 get the error hgcMasterBody is not a member of System.Web.UI.MasterPage 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'. This happens in both of these cases: Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" and Master.hgcMasterBody.Attributes["onkeydown"] = "catchKeyPress(window.event.keyCode, window.event.srcElement);";
Show quote
Hide quote
"Roberto Kohler" <rkoh***@intranetslab.com> wrote in message
news:exryl5MBGHA.1252@TK2MSFTNGP09.phx.gbl... >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'. > > This happens in both of these cases: > Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" > and > Master.hgcMasterBody.Attributes["onkeydown"] = > "catchKeyPress(window.event.keyCode, window.event.srcElement);"; > > Sorry, I made two mistakes:
First off, I used the "[" because I was thinking in C#. You need to use "(" in VB. Now, make this change to your Page_Load: Dim hgcMasterBody As HtmlGenericControl = Master.FindControl("hgcMasterBody") hgcMasterBody.Attributes("bgcolor") = "lightblue" hgcMasterBody.Attributes("onkeydown") = ""catchKeyPress(window.event.keyCode, window.event.srcElement);" Ignore my previous ending semicolon as well (another C# thing). Hope this helps! -- Show quoteHide quoteChristopher A. Reed "The oxen are slow, but the earth is patient." "Roberto Kohler" <rkoh***@intranetslab.com> wrote in message news:exryl5MBGHA.1252@TK2MSFTNGP09.phx.gbl... >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'. > > This happens in both of these cases: > Master.hgcMasterBody.Attributes("bgcolor") = "lightblue" > and > Master.hgcMasterBody.Attributes["onkeydown"] = > "catchKeyPress(window.event.keyCode, window.event.srcElement);"; > >
Datagrid only shows the header
Wizard Control - Referencing buttons in <StepNavigationTemplate> Master Page problem <customErrors mode="Off"/> ERROR Walking thr DataReader Sorting in GridView problem Can RDLC Reports be used with Oracle data sources? Membership roles question Textbox Select Text GridView KeepInEdit Mode problem |
|||||||||||||||||||||||