Last active
March 14, 2016 17:39
-
-
Save kakari2/988ccb0913de8768de3f to your computer and use it in GitHub Desktop.
ASP.NET Inherit Page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MasterPage(aspx) | |
| <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplicationSample.WebForm1" %> | |
| <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> | |
| </asp:Content> | |
| <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> | |
| <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> | |
| </asp:Content> | |
| // MasterPage(.cs) | |
| using System; | |
| namespace WebApplicationSample | |
| { | |
| public partial class WebForm1 : WebApplicationBase.WebFormBase | |
| { | |
| protected void Page_Load(object sender, EventArgs e) | |
| { | |
| // "ab" will be render. "c" will not render. | |
| Response.Write(Session["a"]); | |
| Response.Write(Session["b"]); | |
| Response.Write(Session["c"]); | |
| } | |
| protected void Button1_Click(object sender, EventArgs e) | |
| { | |
| // "abcc" will be render. | |
| Response.Write(Session["c"]); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MasterPage(aspx) | |
| <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplicationSample.Site" %> | |
| // MasterPage(.cs) | |
| using System; | |
| namespace WebApplicationSample | |
| { | |
| public partial class Site : WebApplicationBase.WebApplicationBase | |
| { | |
| protected void Page_Load(object sender, EventArgs e) | |
| { | |
| //Page_Load Event will happen after WebForm1.Page_Load Event. | |
| Session["C"] = "c"; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // WebForm(aspx) | |
| <%@ Page Title="" Language="C#" MasterPageFile="~/WebApplicationBase.Master" AutoEventWireup="true" CodeBehind="WebFormBase.aspx.cs" Inherits="WebApplicationBase.WebFormBase" %> | |
| // WebForm(.cs) | |
| using System; | |
| namespace WebApplicationBase | |
| { | |
| public partial class WebFormBase : System.Web.UI.Page | |
| { | |
| protected void Page_Init(object sender, EventArgs e) | |
| { | |
| Session["b"] = "b"; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MasterPage(aspx) | |
| <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="WebApplicationBase.master.cs" Inherits="WebApplicationBase.WebApplicationBase" %> | |
| // MasterPage(.cs) | |
| using System; | |
| namespace WebApplicationBase | |
| { | |
| public partial class WebApplicationBase : System.Web.UI.MasterPage | |
| { | |
| protected void Page_Init(object sender, EventArgs e) | |
| { | |
| Session["a"] = "a"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment