IronPython for ASP. NET: use shared code

Source: Internet
Author: User

IronPython getting started the second article uses shared code to create a simple IronPython class and use it on the ASP. NET page.

1. Create a Web site and ASP. NET page, and select IronPython as the language.


2. About the App_Script folder. After the first step, a folder named App_Script is automatically created in the new Web site. Here you can add reusable IronPython sharing classes, you can only put classes in this folder, but not other files such as Web Page and User Control.

3. Create a simple shared class. Add a new item in the App_Script folder. The following dialog box is displayed. Select IronPython Module.

Create a simple shared class SampleClass, which has a property TestString. It uses the property () function to specify its access methods SetTestString () and GetTestString (). The Code is as follows:

Class SampleClass:

"Sample class with one property"

_ TestString = ""

Def SetTestString (value ):

_ TestString = value


Def GetTestString ():

Return _ testString

TestString = property (GetTestString, SetTestString)

4. Use the shared class to add related controls on the ASP. NET page, as shown below:

<Div>

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

<Asp: Button ID = "Button1" runat = "server" Text = "Button" OnClick = "button#click"/> <br/>

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

Open the Default. aspx. py file and import the namespace:

Import SampleModule

From SampleModule import SampleClass

Click events for the edit button:

Def button#click (sender, args ):

SC = SampleClass ()

SC. TestString = TextBox1.Text

Label1.Text = SC. TestString

After running, enter TerryLee in the text box and click the following button:

Full sample code download: http://files.cnblogs.com/Terrylee/IronPythonDemo2.rar

Note: This example is from the IronPython getting started tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.