Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • gilpt 33 posts 53 karma points
    May 26, 2011 @ 13:39
    gilpt
    0

    hi... lifecycle question

    hi ....

    i got a question ... since .aspx file are not really exists .. so there is no page lyfecycle and no page.load etc..

    how can i have some server code on page.load of a page ??

    i dont want to use (as a macro  )  a user control lifecycle ... or httpmodule  is there any other option ???

     

    hope i made myself clear ...

     

    thanks

  • Gene Foxwell 17 posts 39 karma points
    May 26, 2011 @ 13:54
    Gene Foxwell
    1

    Assuming I understand what you are getting at, you could try using a template ( master page ) to solve that problem.  You would simply create the template and insert the corresponding life cycle events handlers in that.  Otherwise, I don't believe you can put per page code without use of a Macro.

  • gilpt 33 posts 53 karma points
    May 26, 2011 @ 13:58
    gilpt
    0

    ok... but how can i put some server code on the template ...

    it is like masterpage with no code behind...

     

    like this ...

    <%@ Master Language="C#" MasterPageFile="~/masterpages/umbMaster.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="cp_content" runat="server">
      <div id="content" class="frontPage">
        <umbraco:Item runat="server" field="bodyText"/>
      </div>
    </asp:Content>

     

  • Gene Foxwell 17 posts 39 karma points
    May 26, 2011 @ 14:05
    Gene Foxwell
    1

    You can alter the Master Page file to reference a code behind, or simply add a <script runat="server"> </script> section to your page and add the code there.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    May 26, 2011 @ 14:09
    Lee Kelleher
    0

    Hi gilpt,

    The ASP.NET page lifecycle is still there.  Although the URLs (created by content pages) are virtual; all requests are routed through the root "~/default.aspx".

    As for code-behind in the MasterPage templates - sure why not? It does require adding an extra attribute to the declaration for either "CodeBehind" or "Inherits".

    ... or you can add code inline, like so...

    <%@ Master Language="C#" MasterPageFile="~/masterpages/umbMaster.master" AutoEventWireup="true" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Label1.Text = "Howdy Partner!";
        }
    </script>
    
    <asp:Content ContentPlaceHolderID="cp_content" runat="server">
        <div id="content" class="frontPage">
            <asp:Label runat="server" ID="Label1" />
            <umbraco:Item runat="server" field="bodyText"/>
        </div>
    </asp:Content>

    Cheers, Lee.

  • gilpt 33 posts 53 karma points
    May 26, 2011 @ 14:20
    gilpt
    0

    thank you ... i understood the the options of code behind in the masterpage ...

    but as the page itself lyfe cyle you wrote:

    The ASP.NET page lifecycle is still there.  Although the URLs (created by content pages) are virtual; all requests are routed through the root "~/default.aspx".

    i know the urls are virtual , and every pages routes through  "~/default.aspx". so , can i add a code behide in this page????

    and if so, this code behind (in  "~/default.aspx") is common for all page.. is that correct ??

     

    so in all options , the code behind is common for some pages (in  "~/default.aspx" or in template )

    is that correct ???

     

    thanks a lot

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    May 26, 2011 @ 14:25
    Lee Kelleher
    0

    You could add code behind for the "default.aspx" page ... if you do, I'll need to create a class that inherits from "umbraco.UmbracoDefault" - otherwise you'll bork your front-end completely!  I'd advise against this too - reason being that when you come to do an upgrade, you don't want to overwrite any bespoke changes that you've made.

    In all honesty, I don't really understand what your issue is with using a user-control/macro?  Feels like you're trying to swim upstream, when it's much easier to go with the flow of the cms/framework.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft