[Zope3-dev] Re: Inline code

Jeff Kowalczyk jtk at yahoo.com
Wed Feb 11 10:04:59 EST 2004


Have you considered allowing the page template to inherit/adapt to a
namespace from a python script/module? ASP.Net .aspx pages can inherit
from a class (the module is called 'code-behind'). It does a fair job of
eliminating the need for inline code, while providing a reasonable place
to locate certain unavoidable code that sits between application libraries
and one specific page template, such as a datagrid editing page. The
inherited namespace aims to provide objects and methods that are purely
callable, representable, indexable or iterable to the ZPT.

Their IDE presents the .aspx and .cs file as a pair, Zope could have an
object that provided a TTW editor for the ZPT and the module/script. It
should be transferrable to filesystem developers, although they'd have
fewer reasons to use it.

This ASPX example is for their webform gui controls, but I don't cite it
because of the event handling model, rather because of the economy of
being able to predict your namespace in python module and its tightly
associated template. It would be more relevant to Zope development with
non-gui python objects representing application libraries. The code-behind
module could serve as the python glue to filesystem python libraries and
application, limiting the namespace of variables, method results and
iterables necessary to build the specific ZPT without inline code.

I don't know what the reaction to this idea will be, but if it worked out,
I could imagine having all page templates inherit from / adapt to some
default base module, giving explicit control over the template namespace.

(FWIW: I don't understand giving up XML formedness for the '<%@' tag, either)

hellocodebehindcs.aspx
------------------------------
<%@ Page Language="cs" Src="hellocodebehindcs.cs" Inherits="HelloWebFormCs"%>
<html><head><title>C# ASP.NET application with "Code Behind"</title></head>
<body>
  <p>C# ASP.NET application with "Code Behind"<p>
     <form runat="server" ID="Form1">
       <asp:button runat="server" text="Say Hello" ID="Button1" />
     <p><asp:label runat="server" text="" id="TheLabel" />
      </form>
   </body>
</html>

hellocodebehindcs.cs
------------------------------
public class HelloWebFormCs : System.Web.UI.Page {
   protected System.Web.UI.WebControls.Button Button1;
   protected System.Web.UI.WebControls.Label TheLabel;
   override protected void OnInit(System.EventArgs e) {
      this.Button1.Click += 
         new System.EventHandler(this.Button1_Click);
      base.OnInit(e);
   }
   private void Button1_Click(object sender, System.EventArgs e) {
      TheLabel.Text = 
      "Hello, world! (from an ASP.NET/C# WebForm with code behind)";
   }
}

Excerpted From:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnguinet/html/drguinet0code.asp





More information about the Zope3-dev mailing list