zoukankan      html  css  js  c++  java
  • IronPython for ASP.NET:使用IronPython创建一个简单的Web页面

    IronPython for ASP.NET CTP版发布的消息无疑让人激动,我也迫不及待的下载下来体验一下,根据提供的入门教程写一个最基本的Web页面。在开始之前,你需要下载安装IronPython for ASP.NET CTP版。

    1.打开VS2005,新建Web站点,并选择语言为IronPython

    2.切换Default.aspx页面到设计模式,在窗体上拖放一个TextBoxButtonLabel控件。

    <div>

        
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> &nbsp;

        
    <asp:Button ID="Button1" runat="server" Text="Button"/>

        
    <h3><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></h3>

    </div>

    3.切换到代码文件(Default.aspx.py),可以看到已经导入了一些常用的命名空间

    import System

    from System.Data import *

    from System.Web import *

    from System.Web.UI import *

    from clr import *

    同时还有一个窗体加载事件:

    def Page_Load():

        
    if not IsPostBack:

            
    pass

    这里的pass只是一个占位符而已,并没有什么实际的意义。

    4.编写窗体加载事件代码,在窗体加载时我们显示自己的用户名:

    def Page_Load():

        
    if not IsPostBack:

            Label1.Text 
    = "TerryLee"

    5.编写Button1的单击事件代码:

    def Button1_Click(sender, args):

        Label1.Text 
    = Textbox1.Text

    注意这里代码都要手工输入,不能通过在窗体中双击按钮或者是在属性窗口选择相关事件。

    6.在HTML代码中,为Button1加上Click事件,完成后代码如下:

    <div>

        
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> &nbsp;

        
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br /><br />

        
    <h3><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></h3>

    </div>

    7.激动人心时刻来临,一个很“复杂”的基于IronPythonASP.NET Web页面终于完成了,运行后界面如下:

    文本框中输入cnblogs后单击按钮:

    8.如果不想使用独立的代码文件,在ASPX页面中的代码如下:

    <script runat="server">

    def Page_Load():

        
    if not IsPostBack:

            Label1.Text 
    = "TerryLee"

     
    def Button1_Click(sender, args):

        Label1.Text 
    = Textbox1.Text

    </script>

    使用IronPython创建简单的Web页面就体验到这儿,后面再继续体验其他几个入门教程。

    注:该例子来自于IronPython入门教程。

  • 相关阅读:
    linux查看电脑温度
    sshd_config详解
    Python Matplotlib包中文显示异常解决方法
    "打开jupyter notebook后找不到安装Anaconda的环境"的解决方法
    [7]力扣每日一题
    UML复习回忆
    [6]力扣每日一题
    [4]力扣每日一题
    [3]力扣每日一题
    mybatis 动态创建表、主键、索引、注释
  • 原文地址:https://www.cnblogs.com/Terrylee/p/Creating_a_Basic_Web_Page_with_IronPython.html
Copyright © 2011-2022 走看看