开发者

page_load in system.web.ui.page not called

I have been looking around yet I can't find any that fits in my problem.

I am doing this in c# asp.net visual studio 2005, i have a master page and removed the Page_Load event from there since i wanted the Page_Load in the pages other than the master to fire. So in one of the pages other than the masterpage:

  • in page1.aspx:

    public partial class page1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             (this.Master as IMasterPage).SetSelected("gtm");
        }
    }
    
  • in masterpage.cs:

    public partial class Master : System.Web.UI.MasterPage, IMasterPage
    {
        #region ImasterPage Members
        public void SetSelected(string name)
        {
            switch (name)
            {
                case "gtm": 
                    this.gtm.CssClass = "gtm_sel"; 
                    break;
                default: break;
            }
        }
        #endregion
    }
    

the codes shown are for the horizontal, single-level main menu somewhere on top of page and i wanted the menu selected to highlight after the page reloads but the page_load on the page1.aspx does not seem to be called!

This is the part of the menu in the masterpage:

<div id="menu" class=''>
    <ul>                   
        <li><asp:HyperLink ID="com" CssClass="gtm" runat="server" NavigateUrl="~/page1.aspx"><span>Courses</span></asp:HyperLink></li> 
        <li><asp:HyperLink ID="tbm" CssClass="tbm" runat="server" NavigateUrl="~/page2.aspx"><span>Team Building</span></asp:HyperLink></li>
        <li><asp:HyperLink ID="ptm" CssClass="ptm" runat="server" NavigateUrl="~/page3.aspx"><span>Personal Training</span></asp:HyperLink></li>
        <li><asp:HyperLink ID="atm" CssClass="atm" runat="server" NavigateUrl="~/page4.aspx"><span>Adventure Tours</span></asp:HyperLink></li>
        <li><asp:HyperLink ID="gtm" CssClass="stm" runat="server" NavigateUrl="~/groupTraining.aspx"><span>Group Training</span></asp:HyperLink></li>
    </ul>
</div>

all css styles for hover and selected (eg: gtm_sel) are 开发者_高级运维defined and working properly in the sense that when i bypass the page load even from page1.aspx onto the page_load event of the master page calling it from there like: this.SetSelected('gtm'); it works like a charm

haywired.


Do you have AutoEventWireup="true" in the Page directive...

<%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜