Adding an Icon to the project is completely optional. In order to add an icon to the project, you first have to have an icon. The icon must be 16 pixels by 16 pixels and no more than 16 bit color. I downloaded a free 32x32x16 icon from the web and resized it to 16x16 in PaintShop Pro. Do what you must. Once you have an icon, copy it into the Project directory and name it CountryCodeDropDownList.bmp. The filename for the icon is the same as the name of the Web Control Class.
Here is the icon that I have chosen:
6.1. Solution Explorer
In the Solution Explorer, Right Click the wclProfileControls Project (or whatever you named your project). Select Add. Select Add Existing Item. Change the Files of Type Dropdown List to "All Files" (you may need to scroll down in the list) and Browse to the CountryCodeDropDownList.bmp file and select it. Click Open to add it to the project.
Right Click the CountryCodeDropDownList.bmp file in the Solution Explorer and Select Properties. Click the word Content in Build Action and Select Embedded Resource from the Dropdown List (the down arrow to the right of the word Content).
7. Build the Web Control Library
This is a good checkpoint for building the Web Control Library.
7.1. Solution Explorer
In the Solution Explorer, Right Click on the wclProfileControls Project and Select Build. You should not get any errors and the output will be similar to this:
------ Build started: Project: wclProfileControls, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... The project is up-to-date. Building satellite assemblies... ---------------------- Done ---------------------- Build: 1 succeeded, 0 failed, 0 skipped
8. ASP .NET Web Application
The Web Control is complete and is ready to be consumed by an Application. You will create a simple Web Project to exercise the Web Control.
8.1. New Project
Create a new Project within the Solution for the Web Application.
8.1.1. Solution Explorer
In the Solution Explorer, Right Click the Solution wclProfileControls (top level, not the Project). Select Add. Select New Project. Select Visual C# Projects from the folders on the left. Select ASP .NET Web Application from the Templates window. Change the location to something like http://localhost/ccTest. Click OK and take a look at all of the files that the Project wizard has created for you. In particular, you will be focusing most of your attention on the .aspx and .aspx.cs files.
8.2. Rename .aspx File
Change the generated WebForm1.aspx to default.aspx.
8.2.1. Solution Explorer
In the Solution Explorer, expand the ccTest Project(or whatever you named your project). Right Click on WebForm1.aspx and Click Rename. Name it default.aspx. You will notice that the design view tab now shows default.aspx and that the WebForm1.aspx.cs file has automatically been renamed default.aspx.cs.
8.2.2. Code View
The change of name is not complete until you replace the name WebForm1 in the code itself.
First, make sure that you only have default.aspx (HTML View) and possibly default.aspx.cs open in the Designer. Then, open default.aspx.cs in Code View by Right Clicking on default.aspx and selecting View Code. Check the Option on the Search Panel that says All open documents and Replace all occurences of WebForm1 with wf_ccTest. There should be a grand total of 4 occurences in the 2 files.
8.3. FlowLayout Positioning
Visual Studio defaults to GridLayout for .aspx files. Change it to FlowLayout. The difference is that GridLayout uses absolution pixel positioning (Grid) and FlowLayout uses relative positioning (Flow, things get put next to each other). To change the layout, Click over to the HTML view of default.aspx and change the MS_POSITIONING body attribute to FlowLayout:
<body MS_POSITIONING="FlowLayout">
8.4. Add Web Control to the Toolbox
Now it is time to add the Web Control, that you created earlier, to the Toolbox.
8.4.1. Design View
Click back to the Design View of the default.aspx file.
8.4.2. Toolbox
Find the Toolbox, usually to the left of the workspace. If you cannot see the window anywhere it might be unpinned. If this is the case, you will see a button labeled Toolbox somewhere on screen, simply click it and it will expand. If you want it to stay expanded, you will need to pin it by clicking on the push-pin at the top right of the window. If you cannot see the window or the button anywhere, Click the IDE menu item: View=>Toolbox.
8.4.2.1. My User Controls
The My User Controls Toolbox Tab is where you are going to add the newly created control. To do so, Click on the My User Controls Tab. Right Click in the empty area below the name and Select Add/Remove Items... The Customize Toolbox dialog will appear. Make sure that the .NET Framework Components Tab is selected and Click the Browse... button on the bottom right. Navigate to your project directory - typically in My Documents\Visual Studio Projects\wclProfileControls\bin\debug, which is accessible by the My Projects button to the left of the folder list. Select the dll, wclProfileControls.dll Click the Open Button, this will create an entry in the .NET Framework Components Tab that will be preselected - CountryCodeDropDownList. Click the OK Button to generate an icon and text for a CountryCodeDropDownList control in the Toolbox.
8.5. Using the Web Control
If you used the icon from the project files I generated, you will see a World Map icon next to the Caption CountryCodeDropDownList in the Toolbox, otherwise you will see the default Gear icon - that is fine. It is ready to use. In order to add the control to your Web Project, simply switch to Design View for default.aspx and double click the item in the Toolbox. Alternatively, you can drag it from the Toolbox to the Design View. The IDE will automatically add the correct references to the Project for you to be able to access the Web Control.
8.5.1. Programmatic Access
The Control is only useful because it allows you to drag and drop it into your application and have it do it's country code selection magic, giving you back the Text/Value pair of it's selected item when it gets submitted.
8.5.1.1. Label
Add a label to the form for displaying the values of the DropDownList after the form is submitted. I know kludgy, write me with improvements.
Click just after the DropDownList control in Design View and Press Enter to drop down a line. Drag an ASP Label control from the Web Forms Tab of the Toolbox to the default.aspx Design View. Right Click the Label and view its Properties in the Property Grid. Change the Id to lblKludge and delete its Text.
8.5.1.2. Submit Button
Add a submit button to the form.
Click just after the Label control in Design View and Press Enter to drop down a line. Drag an ASP Button control from the Web Forms Tab of the Toolbox to the default.aspx Design View. Right Click the Button and view its Properties in the Property Grid. Change its text to Submit. No need to write a handler for it, it will automatically submit the form.
8.5.1.3. Page_Load
To actually access the values of the DropDownList from the Web Form, add the following to default.aspx.cs in the Page_Load method:
this.lblKludge.Text = this.CountryCodeDropDownList1.Text + ", " +this.CountryCodeDropDownList1.Value;
8.5.1.4. PreRender Event Handler
First you need to add this line of code to the InitializeComponent Method:
this.PreRender +=new EventHandler(WebForm1_PreRender);
Next you need to create the PreRender Event Handler, add these lines:
private void WebForm1_PreRender(object sender, EventArgs e)
{
this.lblKludge.Text = this.CountryCodeDropDownList1.Text + ", " +this.CountryCodeDropDownList1.Value;
}
- "VS.Net controls, Page 1/5"
- "VS.Net controls, Page 2/5"
- "VS.Net controls, Page 3/5"
- "VS.Net controls, Page 4/5"
- "VS.Net controls, Page 5/5"



0 