
C# ПІДРУЧНИКИ / c# / Hungry Minds - ASP.NET Bible VB.NET & C#
.pdf96.EnterAgetextbox.Visible = true
97.EnterAgetextbox.Text = ""
98.
99.'Setting the Visible property of the Finish button to
100.'true and enabling it. Clicking on the Finish button
101.'completes the data entry.
102.Finishbutton.Visible = true
103.Finishbutton.Enabled = true
104.
105. End Sub
106.
107. Sub Finishbutton_Click(src As Object, E As EventArgs)
108.
109.Dim age As Int32 = 0
110.'Converting the value entered in the Age text to Int32.
111.age = Convert.ToInt32(EnterAgetextbox.Text)
112.
113.'Setting the output values from the resource file on
114.'the Output label, Output Name label, and the Output
115.'Age label.
116.
117.Outputlabel.Text = rm.GetString("OutputStr", cinfo) &
118."<hr align=left width=130>"
119.outputlabel.Visible = True
120.
121.OutputNamelabel.Text = rm.GetString("OuputNameStr", cinfo) & "
122." & EnterNametextbox.Text.Trim()
123.outputNamelabel.Visible = True
125.OutputAgelabel.Text = rm.GetString("OutputAgeStr", cinfo) & "
126." & EnterAgetextbox.Text.Trim()
127.outputAgelabel.Visible = True
128.
129.'Setting the Visible property of the Output label to
130.'true.
131.Outputlabel.Visible = true
132.EnterAgelabel.Enabled=false
133.EnterAgetextbox.enabled=false
134.
135.'Setting the Visible property of the Restart button to
136.'true. Clicking this button refreshes the page.
137. Restartbutton.Visible = true
138.
139. End Sub
140.
141. Sub Restartbutton_Click(src As Object, E As
EventArgs)
142.
143.'Enabling the culture list and setting the selected
144.'index to 0.
145.CultureList.Enabled = true
146.CultureList.SelectedIndex = 0
147.
148.'Enabling the Proceed button.
149.Proceed.Enabled = true
151.'Enabling the Finsh button but setting its Visible
152.'property to false
153.Finishbutton.Enabled = true
154.Finishbutton.Visible = false
155.
156.'Enabling the Name label, Name text box, and the
Name
157.'Next button. Also, setting their Visible property to
158.'false.
159.EnterNamelabel.Enabled = true
160.EnterNamelabel.Visible = false
161.EnterNametextbox.Enabled = true
162.EnterNametextbox.Visible = false
163.EnterNametextbox.Text = ""
164.NameNextbutton.Enabled = true
165.NameNextbutton.Visible = false
166.
167.'Enabling the Age label and Age text box and setting
168.'their Visible property to false. Also, the Visible
169.'property of the Output, Output Name, and Output
Age
170.'labels and Restart button is set to false.
171.
172.Culturelabel.Enabled = true
173.EnterAgelabel.Enabled = true
174.EnterAgelabel.Visible = false
175.EnterAgetextbox.Enabled = true
176.EnterAgetextbox.Visible = false
177.EnterAgetextbox.Text = ""
178.Outputlabel.Visible = false
179.OutputNamelabel.Visible = false
180.OutputAgelabel.Visible = false
181.Restartbutton.Visible = false
182.End Sub
183.
184.Sub ProceedEnabled(src As Object, E As EventArgs)
185.If CultureList.SelectedIndex > 0 Then
186.Proceed.Enabled = true
187.End If
188.End Sub
189.</script>
190.
191.<html>
192.<head></head>
194. <body bgcolor="#99cccc">
195.
196.<form runat="server">
197.<p>
198.
199.<table>
200.<tr><td><b>This is a resource demo<hr>
201.</td></tr> </tr>
202.</table>
203.
204.<table width=600>
205.<tr><td width=450><b><asp:label id="Culturelabel"
206.Text="Please select your culture:"
207. visible=true runat=server/></b></td>
208.<td ><asp:DropDownList id="CultureList"
209.AutoPostBack=true
OnSelectedIndexChanged="ProceedEnabled"
210.runat="server"/></td>
211.<td width=40><asp:button width="90px" Text="Proceed"
212.Enabled=false id="Proceed" onclick="Proceed_Click" runat="server"/></td>
213.</tr>
214.
215.<tr><td><b><asp:label id="EnterNamelabel" visible=false
216.runat=server/></b></td>
217.<td><asp:textbox width="100px" id="EnterNametextbox"
218.visible=false runat="server"/></td>
219.<td><asp:button width="90px" Text="Next" visible=false
220.id="NameNextbutton" onclick="NameNextbutton_Click" runat="server"/></td>
221.</tr>
222.
223.<tr><td><b><asp:label id="EnterAgelabel" visible=false
224.runat=server/></b></td>
225.<td><asp:textbox width="100px" id="EnterAgetextbox"
226.visible=false runat="server"/></td>
227.<td width=80><asp:button width="90px" Text="Finish"
228.Enabled=false id="FinishButton" onclick="FinishButton_Click" runat="server"/></td>
229.</tr>
230.
231.<tr><td colspan=2><b><asp:label id="Outputlabel" visible=false
232.runat=server/></b></td>
233.<td><asp:button width="90px" Text="Restart" visible=false
234.id="Restartbutton" onclick="Restartbutton_Click" runat="server"/></td>
235.</tr>
236.
237.<tr><td><asp:label id="OutputNamelabel" visible=false runat=
238.server/></b></td>
239.
240. </tr>
241.
242.<tr><td><asp:label id="OutputAgelabel" visible=false runat=server/></b></td>
243.</tr>
244.
245. </table>
246.
247.</form>
248.</body>
249.</html>
This program prompts users for their name and age. After a user clicks the Finish button, the information is displayed. The text is adjusted according to the culture selected by the
user. The output of this program is shown in Figure 20-2, which is displayed at the beginning of this section.
Summary
In this chapter, you learned the concepts related to international applications. First, you learned the configuration settings for global applications in the Web.config file. Next, you learned about the CultureInfo and RegionInfo classes and their implementation to access culture-specific information. Then, you learned the different classes in the System.Resources namespace. Finally, you learned how to create resource files and implement them to create localized versions of global applications.
Chapter 21: Deploying ASP.NET Applications
Overview
After a Web application is developed, it needs to be deployed to make it available as a Web site. A Web application may be made up of a number of files and components. These components may be developed by the application developer or by a third party. Therefore, while deploying a Web application, you must determine the files to be included in the deployment. In addition, you must determine the method to be used for deploying an application. In this chapter, you will learn about creating deployment projects, specifying configuration settings, and deploying classes and assemblies in ASP.NET.
Introduction to Deployment Projects
Deployment is the process of packaging all files that make up an application and distributing them for the purpose of installation on other computers. Deploying an ASP.NET application can be as easy as copying the application files to the machine on which the application needs to be deployed. When you deploy an application by copying files, no Registry entries are made. To deploy more complex applications, which may comprise various components, you may create deployment projects in Visual Studio
.NET.
A deployment project enables you to specify the files to be included in the deployment, the method by which the application files will be deployed, and the location where the application is to be deployed. In this section, you will look at the different types of deployment projects, the process of creating a deployment project, adding files to the deployment project, and building the deployment project.
Choosing the type of deployment projects
Visual Studio .NET provides different types of deployment projects. The choice of a particular type of deployment project depends upon the application or the component that you want to deploy and the mode of deployment. For example, you may want to deploy an application in the form of a collection of cabinet (CAB) files for downloading the application.
The different types of deployment projects provided in Visual Studio .NET are as follows:
§Merge module project: Creates a single package that contains all files, resources, Registry entries, and the setup logic necessary for deploying the package. A merge module is similar to a dynamic link library (DLL), which allows multiple applications to share code. The only difference in this case is that a merge module allows sharing of the setup code. A
merge module project file has the extension .msm. You cannot use a merge module file by itself. You must merge the resulting .msm file with another deployment project, which creates a Windows Installer (MSI) file.
You can use a merge module project when you want to deploy a component that will be shared by multiple applications, because a merge module project identifies all the dependencies for a component and ensures that the correct versions of the components are installed. Thus, problems relating to versioning can be avoided with merge module projects. When a new version of a component needs to be deployed, you simply create a new merge module project that contains the dependencies for the new version of the component.
§Setup project: Enables you to create a Windows Installer (MSI) file for deploying an application. The resulting MSI file contains the application, dependencies, information about the Registry entries to be made, and installation instructions. A setup project can be used for deploying standard Windows-based applications. When you execute the resulting MSI file, all files related to the application are copied to the Program Files directory on the target computer.
While selecting between a merge module project and a setup project, you must consider the target audience. If the application is intended for use by an end user, you should package all the files for the application in an MSI file. On the other hand, DLLs, controls, and resources that are intended for use by developers should be packaged in a merge module, which can then be packaged by the developer in an MSI file for distribution to the end user.
§Web setup project: Is similar to a setup project. This type of project also results in the creation of an MSI file, which can be used for deploying an application. When you execute the MSI file, all files that make up the application are copied to the virtual root directory on the Web server. This type of project should be used for installing a Web application on a Web server.
§Cab project: Enables you to generate CAB files of a specific size. These CAB files can be used to download components to a Web browser. You can create a cabinet project if you want your component to run on the client instead of the Web server.
You can determine the type of deployment project to be created based on the guidelines given here.
In addition to these types of projects, Visual Studio .NET also provides the Setup Wizard, which creates a basic setup project. It guides you through the steps of creating a deployment project. During each step, the wizard collects information, such as the files to be included in the deployment project.
Creating a deployment project
After determining the type of deployment project, you can create it by following these steps:
1.Open the project that needs to be deployed.
2.Select File → New → Project.
3.Select Setup And Deployment Projects from the Project Types pane.
4.Select the type of deployment project that you want to create from the Templates pane.
5.Change the name of the deployment project to Setup1. Click the Add To Solution radio button.
6.If you select the Setup Wizard, it takes you through the various steps. Each step prompts you to enter the required information, such as the type of project (whether you want to create an MSI file or CAB files), the type of application (Windows application, Web application, merge module for Windows Installer, or downloaded CAB file), and the files to be included in the project.

If you select one of the project types instead of the wizard, it opens the File System Editor, shown in Figure 21-1.
Figure 21-1: File System Editor
Working with editors in a deployment project
While creating a deployment project, you might want to specify the files to be included in a project and the Registry entries to be made when the application is deployed. You might also want to customize the user interface provided at the time of installing an application. You can easily accomplish these tasks by using one of the editors provided in a deployment project. These editors are discussed in the next sections.
File System Editor
The File System Editor enables you to add or remove various files, components, and project output in the deployment project. The File System Editor displays the folders that correspond to the folder structure on the target computer.
Adding and removing folders
You can add your own folders to the deployment project by using the File System Editor. To add a folder, follow these steps:
1.If the File System Editor is not open, open it by clicking the File System Editor button in the Solution Explorer, as shown in Figure 21-2.
Figure 21-2: File System Editor button in Solution Explorer
2.Select the File System On Target Machine node and select Action → Add Special Folder → Custom Folder.
3.Type the name of the folder to be created on the target computer.
To remove a folder from the File System Editor of the deployment project, click the folder and select Edit → Delete.
Adding and removing files
You may want to include files such as Readme.txt, a rich text file containing the license agreement, and some GIF files in a deployment project. You can include these files by following these steps:
1.Select the folder in which the file is to be included.
2.Select Action → Add → File. This invokes the Add Files dialog box.
Note |
You can also select the Project → Add to add files, project outputs, |
|
and components to the deployment project. However, this will result in |
||
|
||
|
adding the item to the application folder instead of the folder of the |
|
|
target computer. |
3.Browse to the folder in which the file is stored and select the file.
Note |
You can also add an assembly file by using this procedure. |
|
To remove a file from the File System Editor, select the file and select Edit → Delete.
Adding and removing project outputs
You can add or remove project outputs from a deployment project. Project outputs may include the EXE and DLL files that are created when you build a project and the source code of the project.
Note
The steps for adding project outputs of one or more projects are as follows:
1.In the File System Editor, select the target folder in which the project outputs are to be included.
2.Click Action → Add → Project Output. This invokes the Add Project Output Group dialog box, shown in Figure 21-3.

Figure 21-3: Add Project Output Group dialog box
3.Select the project from the Project drop-down list.
4.Select the project output group from the list box below the Project drop-down list. These groups include Primary Output, Localized Resources, Debug Symbols, Content Files, and Source Files. When you select a group, the description for the group is displayed in the Description text box. Each of the project output group is described as follows:
§Primary Output: Contains the DLL or EXE built by the project.
§Localized Resources: Contains satellite
Cross-
Reference
§Debug Symbols: Contains the debugging files for the project.
§Content Files: Contains all the content files in the project.
§Source Files: Contains all source files in the project.
5.Click OK.
To remove a project output from the deployment project, select the project output group to be deleted and click Edit → Delete.
Registry Editor
You may want to access the Registry and set values of existing Registry keys or add new Registry keys to the target computer. The Registry Editor enables you to add your own Registry keys and their values to a deployment project. When you execute the deployment project, the Registry keys are added to the Registry of the target computer. When you open the Registry Editor, it displays a standard set of keys, which correspond to the keys in the Windows Registry of the target computer. Figure 21-4 depicts the Registry Editor.

Figure 21-4: Registry Editor
Adding and removing a Registry key
To add a Registry key to the deployment project, follow these steps:
1.Open the Registry Editor by clicking the Registry Editor button in Solution Explorer of the deployment project, as shown in Figure 21-5.
Figure 21-5: Registry Editor button in Solution Explorer
2.Click one of the top-level key nodes: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, or User/Machine Hive.
3.Select Action → New Key. This adds the new key under the toplevel key node that you selected. The new key has a default name. Change the name of the key by typing the new name or by changing the Name property from the Properties window.
You can remove a Registry key from the Registry Editor of the deployment project simply by clicking the key and pressing the Delete key on the keyboard.
Adding and removing Registry values
You can add values to the existing or newly added keys by using the Registry Editor. When you install the application, the Registry key value will be written to the Registry of