IronPython for ASP.NET:使用共享代码
IronPython入门教程第二篇使用共享代码,创建一个简单的IronPython类,并在ASP.NET页面中使用它。
1.创建Web站点和ASP.NET页面,选择语言为IronPython。
2.关于App_Script文件夹。经过上面第一步操作后,新建Web站点中会自动创建一个名为App_Script的文件夹,在这里你可以添加一些可重用的IronPython共享类,在该文件夹下只可以放类,而不能放其它诸如Web Page,User Control等文件。
3.创建一个简单的共享类。在App_Script文件夹中添加新项,会弹出如下对话框,选择IronPython Module。
创建一个简单的共享类SampleClass,在该类中有一个属性TestString,它通过property()函数来指定它的访问方法SetTestString()和GetTestString(),代码如下:
















4.使用共享类,在ASP.NET页面中添加相关的控件,如下所示:









打开Default.aspx.py文件,导入命名空间:



编写按钮的单击事件:







运行后在文本框中输入TerryLee,单击按钮如下:
完整示例代码下载:https://files.cnblogs.com/Terrylee/IronPythonDemo2.rar
注:该例子来自于IronPython 入门教程。
支持TerryLee的创业产品Worktile
Worktile,新一代简单好用、体验极致的团队协同、项目管理工具,让你和你的团队随时随地一起工作。完全免费,现在就去了解一下吧。
https://worktile.com
Worktile,新一代简单好用、体验极致的团队协同、项目管理工具,让你和你的团队随时随地一起工作。完全免费,现在就去了解一下吧。
https://worktile.com