News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Web Programming with J#

Started by sukishan, Jul 14, 2009, 03:30 PM

Previous topic - Next topic

sukishan

Web Programming with J#

While creating Web pages, you can use the Toolbox for adding graphical components to a form. This section shows you how to create and add your own components to the Toolbox.

How to: Create a Component that Runs in the Browser

Components are reusable libraries that inherit from System.ComponentModel.Component. You can use components in the same way as other libraries.

The following example shows you how to create a library component, add it to a Web page, and deploy the component on a Web site. The Web page (.aspx) requests a street address for the South African corporate office. When the component receives this request, it returns the address for a company's Cape Town branch.

To create the componentFrom the File menu, point to New, and then click Project to open the New Project dialog box.

In the New Project dialog box, select the Class Library project template from the list of J# Projects, and type BrowserComponent in the Name box.

On the Project menu, click Add Component.

In the Add New Item dialog box, select Component Class and type BrowserComponent.jsl in the Name box.

A component named BrowserComponent.jsl is added to your class library.

In Solution Explorer, right-click BrowserComponent.jsl, and click View Code.

The code editor opens. Notice that System.ComponentModel.Component is displayed immediately after public class BrowserComponent. By default, a component inherits from the Component class provided by the system. The Component class provides many features for your component, including the ability to use designers.

In Solution Explorer, right-click Class1.jsl, and click Delete. This removes the default class for the class library, because you will not be using it for this particular component.

On the File menu, click Save All to save the project.

In BrowserComponent.jsl, add the following method:



public String[] GetCompanyAddress(int CorpCode) throws IllegalArgumentException
    {
        String Address[];
        switch (CorpCode)
        {
            case 0:
                Address = new String[4];
                Address[0] = "1234 White Street";
                Address[1] = "Sturtevant";
                Address[2] = "WI";
                Address[3] = "53177";
                break;
            case 1:
                Address = new String[4];
                Address[0] = "oltke Moes vei 39";
                Address[1] = "0852";
                Address[2] = "OSLO";
                break;
            case 2:
                Address = new String[3];
                Address[0] = "Parliament Street";
                Address[1] = "Cape Town";
                Address[2] = "S. Africa";
                break;
            default:
                throw new IllegalArgumentException();
        }
        return Address;
    }This method supplies the appropriate customer service location based on a ficitious corporate code. A case statement manages the content to return.

On the Build menu, click Build Solution.


The library compiles. However, at this point, since no client calls the component, you can only compile the component.
A good beginning makes a good ending