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.