Events in ASP.NET Master and Content Pages

  1. Content page PreInit event.

  2. Master page controls Init event.

  3. Content controls Init event.

  4. Master page Init event.

protected void Page_Init(object sender, EventArgs e)
{
       //do something
}
  1. Content page Init event.

  2. Content page Load event.

  3. Master page Load event.

  4. Master page controls Load event.

  5. Content page controls Load event.

  6. Content page PreRender event.

  7. Master page PreRender event.

  8. Master page controls PreRender event.

  9. Content page controls PreRender event.

  10. Master page controls Unload event.

  11. Content page controls Unload event.

  12. Master page Unload event.

  13. Content page Unload event.

public class PageHelper
    {
        public static string CurrentPageModuleId
        {
            get
            {
                return Convert.ToString(HttpContext.Current.Request.QueryString["mid"]);
            }
        }

        public bool HasPagePermission()
        {
            if (string.IsNullOrEmpty(CurrentPageModuleId))
                return false;

            return HasPagePermission(CurrentPageModuleId);
        }

        public bool HasPagePermission(string moduleId)
        {
            return true;
        }

        public bool HasFunctionPermission(string moduleFunctionType)
        {
            if (string.IsNullOrEmpty(CurrentPageModuleId))
                return false;

            return HasFunctionPermission(CurrentPageModuleId, moduleFunctionType);
        }

        public bool HasFunctionPermission(string moduleId, string moduleFunctionType)
        {
            return true;
        }
    }

如使用BasePage, BasePage中的page_load会在content page load event 之前被执行

可使用该放在<head>中添加需要的js file and css file, 只需要在<head>中加上<head runat="server">

if (Page.Header != null)
            {
                LiteralControl jsResource = new LiteralControl();
                string src = ResolveUrl("~/js/mini-template-control.js");
                jsResource.Text = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", src);
                Page.Header.Controls.AddAt(, jsResource);

                HtmlLink stylesLink = new HtmlLink();
                stylesLink.Attributes["rel"] = "stylesheet";
                stylesLink.Attributes["type"] = "text/css";
                stylesLink.Href = ResolveUrl("~/css/mini-template-control.css");
                Page.Header.Controls.AddAt(, stylesLink);
            }

            if (!this.IsPostBack)
            {
                string mid = Convert.ToString(HttpContext.Current.Request.QueryString["mid"]);
                if (string.IsNullOrEmpty(mid))
                {
                    Response.Redirect(ResolveUrl("~/About.aspx"));
                }
            }
上一篇:jQuery校验文件格式及大小


下一篇:Flowplayer-Setup