Random ...
 
December 2017
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Tags ...
Links



python+zope++:: IronPython on ASP.Net
Posted at 12.Aug,2008 07:46  Comments 0 / Trackbacks 0 / Like this post!
Technorati tag(s):

I'm attending an introduction ASP.Net course and said to myself, why not make things more interesting and put IronPython into the mix.

IronPython, for those not in the know, is not a metal band, although it would make a great band name :P. IronPython is python on .Net.

ASP.Net can be coded with any .Net languages (c#.net, vb.net) and since IronPython is a .Net language, we can code IronPython for ASP.Net.

Get IronPython Studio , to make life easier.

Get the .net framework, at least 2.0, to start coding.

Start IronPython, and create a new website. We will be presented with two files, the presentation (Default.aspx) and the logic (Default.aspx.py)

Pretty much what I do for my Zope 2, add Page Templates and make use of Script (Python).

Another exercise involved creating forms and getting all the passed info. The presentation code/html:

 <%@ Page Language="IronPython" CodeFile="Default3.aspx.py" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 147px;
        }
        .style2
        {
            width: 372px;
        }
    </style> 
 </head>
 <body>
    <form id="form1" runat="server">

        <br />
        <table style="width:100%;">
            <tr>
                <td class="style1">
                    Full Name</td>
                <td class="style2">
                    <asp:TextBox ID="tFullname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Age</td>
                <td class="style2">
                    <asp:TextBox ID="tAge" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Sex</td>
                <td class="style2">
                    <asp:RadioButtonList ID="rSex" runat="server">
                        <asp:ListItem Value="M">Male</asp:ListItem>
                        <asp:ListItem Value="F">Female</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Courses</td>
                <td class="style2">
                    <asp:CheckBoxList ID="cCourses" runat="server">
                        <asp:ListItem Value="cs">c#.net</asp:ListItem>
                        <asp:ListItem Value="vb">vb.net</asp:ListItem>
                        <asp:ListItem Value="js">j#.net</asp:ListItem>
                        <asp:ListItem Value="cp">c++.net</asp:ListItem>
                    </asp:CheckBoxList>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Student type</td>
                <td class="style2">
                    <asp:DropDownList ID="dStudentType" runat="server">
                        <asp:ListItem Value="ft">Full-time</asp:ListItem>
                        <asp:ListItem Value="pt">Part-time</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;</td>
                <td class="style2">
                    <asp:Button ID="bRegister" runat="server" onClick="cmdRegister" Text="Register" />
                </td>
            </tr>
        </table>

    <p>
        &nbsp;</p>
    <p>
        &nbsp;</p>
    </form>
    <div id="res" runat="server">

    </div>

 </body>
 </html>

and the cmdRegister handler code:

  def cmdRegister(sender, e):
     res.InnerHtml = """
                        Thank you <b>%s</b> for registering .
                        You are a %s year old %s. You're studying %s<br />
                        You enrolled in: <br />&raquo; %s
                        """ % (tFullName.Text, tAge.Text, rSex.SelectedItem.Text, dStudentType.Text,
                              '<br />&raquo; '.join([cCourses.Items[x].Text for x in xrange(0,cCourses.Items.Count) if cCourses.Items[x].Selected])

                      )

We're supposed to have a brief intro to c# today. We'll see the solution for the above.

Snapshots:

default presentation the Page_Load


Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/200/tbping 

Comments
Post a comment