Using Dynamic Languages with ASP.NET

07/09/2009

This walkthrough provides you with an introduction to dynamic languages for ASP.NET. It guides you through creating a simple page in Microsoft Visual Studio, adding controls, and adding event handlers using dynamic languages.

Tasks illustrated in this walkthrough include:

  • Adding controls to the default page.
  • Adding event handlers in a separate code file, using dynamic languages.
  • Adding a second page with event-handling code in the page.
Prerequisites

In order to complete this walkthrough, you will need:

  • Microsoft Visual Studio 2008 or Visual Web Developer 2008 Express Edition.
  • A copy of the website included in the ASP.NET Dynamic Language Support download. There is currently no project template, so it is necessary to copy the website in order to start with a blank ASP.NET Dynamic Language website.

This walkthrough assumes that you have a general understanding of working in Visual Web Developer. For an introduction, see Walkthrough: Creating a Basic Page in Visual Web Developer.

Creating a Web Site

In this part of the walkthrough, you will create a Web site with a dynamic language as the default language.

To create a Web site with a default ASP.NET Web page

  1. Copy the files from the ASP.NET Dynamic Language Support project into an empty directory.
  2. In Visual Studio (or Visual Web Developer), in the File menu, click Open Web Site. The Open Web Site dialog box is displayed.
  3. Select the directory in which you copied the files in step 1. Make sure that FileSystem is selected in the left panel of the dialog.

    Note: You can use statically compiled languages in the same Web application by creating pages and components in different programming languages.

  4. Click Open. Visual Studio opens the folder as a website and displays the files in the Solution Explorer.
Adding Controls to the Default Page

In this part of the walkthrough, you will add server controls to the page.

To add controls to the page

  1. Switch to Design view.
  2. In the Toolbox, from the Standard group, drag three controls onto the page: a TextBox control, a Button control, and a Label control.
  3. Put the insertion point above the TextBox control, and then type Enter your name: to create a caption for the text box.
Programming the Button Control

For this walkthrough, you will write code that reads the name that the user enters into the text box and then displays the name in the Label control.

To add a button event handler

  1. Right-click the page and click View Code to show the separate code file. For example, if you are using IronPython, the file is Default.aspx.py.

    The file contains a stub event handler for the Load event of the page.

    Note: In IronPython, pass is a placeholder that does nothing.

  2. Replace the stub event handler with the following code to set the label text when the page is initialized:

    IronPython

    		
    def Page_Load(sender, e):
    if not IsPostBack:
    Label1.Text = "...Your name here..."
  3. Add the following code to create an event handler for the button's Click event:

    IronPython

    		
    def Button1_Click(sender, e):
    Label1.Text = Textbox1.Text

    In this release, event handlers must be coded and bound manually. You cannot create them by double-clicking a control in Design view or by selecting an event in the Properties window.

    Because dynamic languages do not have typed parameters and variables, you do not need to know the type of the event argument object.

    Note: In this release, IntelliSense support for dynamically typed variables is limited. You can press CTRL+SPACE to get a list of code elements that are currently in scope.

  4. Switch to Default.aspx and go to Source view, and then bind the event handler by adding an OnClick attribute to the Button control markup, as shown in the following example:
    <form id="form1" runat="server">
    <div>
    Enter your name:<br />
    <asp:TextBox ID="TextBox1" runat="server">
    </asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button"
    OnClick="Button1_Click"/><br />
    <br />
    <asp:Label ID="Label1" runat="server" Text="Label">
    </asp:Label>
    <br />
    </div>
    </form>
  5. Press CTRL+F5 to run the page in the browser using the ASP.NET Development Server.
  6. Enter a name into the text box and click the button. The name you entered is displayed in the Label control. If the name does not appear, check the spelling of the event handler in the OnClick attribute.
  7. In the browser, optionally view the source of the page you are running.
  8. Close the browser.
Programming the Button Control

For this walkthrough, you will add dynamic language code in a script block.

To add a default button event handler

  1. Switch to Source view.
  2. Add the following code to initialize the label and to create an event handler for the button's Click event.

    IronPython

    		
    <script runat="server">
    def Page_Load(sender, e):
    if not IsPostBack:
    Label1.Text = "...Your name here..."
    
    def Button1_Click(sender, e):
    Label1.Text = Textbox1.Text
    </script>
  3. In the Button control, bind the event handler by adding the OnClick attribute, as you did previously in this walkthrough. The following example shows the markup.
    <asp:Button ID="Button1" runat="server" Text="Button"
    OnClick="Button1_Click"/><br />
  4. Press CTRL+F5 to run the page in the browser using the ASP.NET Development Server.
Posted in: .NET Framework| Tags: asp.net Dynamic Data Control IronPython Website Dynamic Language Support Page

Web Development in VSTS 2010

07/09/2009

With ASP.NET Microsoft delivered a ground breaking productive development model that made web applications accessible to the traditional application developer. Over the last few releases not only has the tooling in Visual Studio improved to provide developers with a more web standard set of tools but to provide leading features like CSS property grids and split view design surfaces.
H
owever the industry evolves and so do the tool requirements and patterns that developers use. Web developers are leading the push to split content from data and to use a Test Driven Development (TDD) methodology. In Visual Studio 2010 we deliver the next generation of ASP.NET web tools that make it easy for developers to use TDD to build Model-View-Controller (MVC) based web sites.
Many ASP.NET Developers have already experienced the preview release of ASP.NET MVC and all the features in that release are included in Visual Studio 2010. Ranging from Project Templates and Solutions that natively describe an ASP.NET MVC website to automatic generation of test projects in the web solutions to wizard support for common tasks like creating views from controllers and snippet support for HTML Markup, the Visual Studio IDE delivers all the support required.
In Visual Studio 2008 we invested heavily in supporting JavaScript in the Visual Studio IDE and debugger. In Visual Studio 2010 we’re continuing that investment with a higher performance and standards compliant JavaScript IntelliSense engine. These investments enabled Microsoft to announce their involvement with the JQuery group and Visual Studio 2010 will be the first version of Visual Studio to ship JQuery as a native part of the ASP.NET solution set.
Deployment of websites has been a challenge for developers for many years and Visual Studio 2010 has full IDE support for a simplified deployment process for ASP.NET websites. Called “One Click Deployment”, this process and IDE support provides a wizard, dialogs and design surfaces that make it simple for developers to identify the components of a website that need to be deployed and handle the process of moving them from the development machine to the web server, whether that is an internal server for the organization or a server hosted by a 3rd party site.
“One Click Deployment” also solves the problem of changing the settings of a website from the development machines to the final deployed site. Many times developers have sent websites to deployment with debug tracing turned on or the database connections set to the development servers. With web.config transformations, “One Click Deployment” enables a developer to create a custom set of transforms that will be applied to the website every time it is deployed and ensures that the appropriate settings are in the configuration files.
Additionally Microsoft has just released the Silverlight 2 runtime and tooling for Visual Studio 2008. In Visual Studio 2010 Silverlight is fully supported for developers wishing to build Silverlight content. Having design surfaces for Silverlight enables developers to either author original content or to modify content as part of the designer-developer workflow that Visual Studio enabled in the last release. Visual Studio 2010 also provides full debugging support for Silverlight and provides project system integration for developers consuming this content in various applications types, for example web developers building ASP.NET websites will be able to include existing Silverlight content and Visual Studio will create the appropriate test pages and content includes to enable them to focus debugging on the Silverlight content in the context of the overall website solution.

Posted in: .NET Framework| Tags: Website VSTS VSTS 2010 .NET 4.0 Beta Web Development

Using Access Data on an ASP.NET Web Page

06/21/2009

You can now use the database in a Web page. This part of the walkthrough uses an AccessDataSource control and a DataList control.

To add AccessDataSource and DataList controls to the page

  1. Open the Default.aspx page (or another page that you want to use) and switch to Design view.
  2. From the Data group in the toolbox, drag an AccessDataSource control onto the page.

    Note  If the Access Data Source Tasks menu does not appear, right-click the control and then click Show Smart Tag.

  3. On the Access Data Source Tasks shortcut menu, click Configure Data Source. The Configure Data Source wizard is displayed.
  4. On the Choose a database page, in the Microsoft Access Data file box, type ~/App_Data/Northwind.mdb or use the Browse button to select the .mdb file.
  5. Click Next to open the Configure Select Statement page, and then click Specify columns from a table or view.
  6. In the Name list, click Categories.
  7. Select the CategoryName and Description check boxes and then click Next.
  8. Optionally, click Test Query to test your query.
  9. Click Finish.
  10. From the Data group in the toolbox, drag a DataList control onto the page.
  11. On the DataList Tasks menu, in the Choose Data Source box, click AccessDataSource1.
  12. Click Ctrl+F5 to run the page with the default layout.
  13. Close the browser.
Posted in: Website-asp.net| Tags: asp.net Dynamic Data DataList Website Access Data Page Access database asp web accessdatasource

Databinding with Dynamic Languages for ASP.NET

06/21/2009
Prerequisites

In order to complete this walkthrough, you will need the following:

  • Microsoft Visual Studio 2008 or Visual Web Developer 2008 Express Edition.
  • A copy of the website included in the ASP.NET Dynamic Language Support download. There is currently no project template, so it is necessary to copy the website in order to start with a blank ASP.NET Dynamic Language website.
  • The Northwind.mdb file that contains the Access version of the sample Northwind database. This file is included in the ASP.NET Quickstarts. If you installed the ASP.NET Quickstarts with Visual Studio, the file is located in the QuickStart\aspnet\samples\data\App_Data folder. Alternatively, you can use another database and adjust the steps in the walkthrough to match the database and tables that you are using.

 

Creating the Web Site and Page

If you have already created a Web site in Visual Studio (for example, by working with the companion walkthrough Using Dynamic Languages with ASP.NET), you can use that Web site and go to the next part of the walkthrough, where you add an Access database to the project. Otherwise, create a new Web site and page by following these steps.

To create a Web site with a default ASP.NET Web page

  1. Copy the files from the ASP.NET Dynamic Language Support project into an empty directory.
  2. In Visual Studio (or Visual Web Developer), in the File menu, click Open Web Site. The Open Web Site dialog box is displayed.
  3. Select the directory in which you copied the files in step 1. Make sure that FileSystem is selected in the left panel of the dialog.

    Note: You can use statically compiled languages in the same Web application by creating pages and components in different programming languages.

  4. Click Open. Visual Studio opens the folder as a website and displays the files in the Solution Explorer.

Next you will add the Northwind.mdb Access database or your own database to the Web application project.

To add an Access database to the project

  1. If the Web site does not already contain an App_Data folder, in Solution Explorer, right-click the name of your Web site, click Add ASP.NET Folder, and then click App_Data.
  2. In Visual Studio, in Solution Explorer, right-click the App_Data folder, and then click Add Existing Item.
  3. In the Add Existing Item dialog box, browse to the Northwind.mdb file, and then click Add.
Posted in: Website-asp.net| Tags: .NET asp.net Dynamic Data Prerequisites Website database asp dynamic visual file walkthrough order

Hot Posts

Latest posts

Tags

Others

Sponsors