IronPython for ASP. NET: Use IronPython to create a simple Web page

Source: Internet
Author: User

The message released by IronPython for ASP. net ctp is no doubt excited. I can't wait to download it and try it out. I will write a basic Web Page Based on the tutorials provided. Before you start, you need to download and install IronPython for ASP. net ctp.

1. Open VS2005, create a Web site, and select IronPython as the language.


2. Switch the Default. aspx page to the design mode, and drag and drop a TextBox, Button, and Label control on the form.

<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>

</Div>

3. Switch to the code file (Default. aspx. py). You can see that some frequently-used namespaces have been imported.

Import System

From System. Data import *

From System. Web import *

From System. Web. UI import *

From clr import *

There is also a form loading event:

Def Page_Load ():

If not IsPostBack:

Pass

The pass here is just a placeholder and has no practical significance.

4. Compile the form loading Event code. When the form is loaded, We will display our Username:

Def Page_Load ():

If not IsPostBack:

Label1.Text = "TerryLee"

5. Compile the Click Event code for Button1:

Def button#click (sender, args ):

Label1.Text = Textbox1.Text

Note that the code here must be manually entered. You cannot double-click the button in the form or select related events in the Properties window.

6. In the HTML code, add a Click event to Button1. The Code is as follows:

<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>

7. An exciting moment is approaching. A very "complicated" IronPython-Based ASP. NET Web page is finally completed. The interface after running is as follows:

Enter cnblogs in the text box and click:

8. If you do not want to use an independent code file, the code on the ASPX page is as follows:

<Script runat = "server">

Def Page_Load ():

If not IsPostBack:

Label1.Text = "TerryLee"

 
Def button#click (sender, args ):

Label1.Text = Textbox1.Text

</Script>

You can use IronPython to create a simple Web page and try other tutorials later.

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.