Beruflich Dokumente
Kultur Dokumente
Console.WriteLine(person1.name); // Call the constructor that has one parameter. Person person2 = new Person("Sarah Jones"); Console.WriteLine(person2.name); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey();}} // Output: // unknown // John Smith // Sarah Jones 2. Describe the following with respect to creating Web Forms in .Net environment: a. Web Form Life Cycle b. Creating a Web Form Write programs with corresponding output screens to demonstrate the above concepts. Answer :a. Web Form Life Cycle Every request for a page made from a web server causes a chain of events at the server. Theseevents, from beginning to end, constitute the life cycle of the page and all its components. The life cycle begins with a request for the page, which causes the server to load it. When therequest is complete, the page is unloaded. From one end of the life cycle to the other, the goal is to render appropriate HTML output back tothe requesting browser. The life cycle of a page is marked by the following events, each of which you can handle yourself or leave to default handling by the ASP.NET server: Initialize Load ViewState Process Postback Data Load Send Postback Change Modifications Handle Postback Events PreRender Save State Render Dispose
b. Creating a Web Form To create the simple Web Form that will be used in the next example, start up Visual Studio .NETand open a New Project named Programming CSharpWeb . Select the Visual C# Projects folder (becauseC# is your language of choice), select ASP.NET Web Application as the project type, and type in its name, Programming CSharp Web. Visual Studio .NET will display http://localhost/ as the default location.
When you create a new Web Form application, Visual Studio .NET will generate a bitof boilerplate code to get you started
Q3. Design a simple Window based form application to perform basic arithmetic operations.
Answer : 3. Design a simple Window based form application to perform basic arithmetic operations We have to write the following code in the .cs file using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Formnamespace Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string i, j; static char c; private void btnthree_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(3); } private void btnone_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(1); } private void btntwo_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(2); } private void btnfour_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(4); } private void btnfive_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(5); } private void btnsix_Click(object sender, EventArgs e)
{ textBox1.Text += Convert.ToString(6); } private void btnseven_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(7); } private void btneight_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(8); } private void btnnine_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(9); } private void btnzero_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(0); } private void btnplus_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '+'; } private void btnminuse_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '-'; } private void btnmultiply_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '*'; } private void btndivide_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '/'; }
private void btnmodulo_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '%'; } private void btnequal_Click(object sender, EventArgs e) { j = textBox1.Text; calclocalhost.CalcWebService obj = new calclocalhost.CalcWebService(); textBox1.Text = obj.calculate(i, j, c); } } } Run the application. Output:
Q4) Describe the following with respect to State Management in ASP.Net: a. Cookies in ASP.NET b. Session State c. Application State Answer : a. Cookies in ASP.NET Cookies provide a means in Web applications to store user-specific information. For example, when auser visits your site, you can use cookies to store user preferences or other information. When the uservisits your Web site another time, the application can retrieve the information it stored earlier.A cookie is a small bit of text that accompanies requests and pages as they go between the Web serverand browser. The cookie contains information the Web application can read whenever the user visits the site . You can add cookies to the Cookies collection in a number of ways. b. Session State
.ASP.NET session state is enabled by default for all ASP.NET applications. ASP.NET sessionstatevariables are easily set and retrieved using the Session property, which stores session variable values as acollection indexed by name. For example, the following code example creates the session variablesFirstName and LastName to represent the first name and last name of a user, and sets them to valuesretrieved from TextBox controls. C# Code Session["FirstName"] = FirstNameTextBox.Text; Session["LastName"] = LastNameTextBox.Text; c. Application State Application state is a data repository available to all classes in an ASP.NET application.Application state is stored in memory on the server and is faster than storing and retrieving information ina database. Unlike session state, which is specific to a single user session, application state applies to allusers and all sessions. Therefore, application state is a useful place to store small amounts of often-useddata that does not change from one user to another. The following example shows an object declaration foran application state value:<object runat="server" scope="application" ID="MyInfo"PROGID="MSWC.MYINFO"></object>.
Q5. Describe the following with respect to Web Services in .Net: a. Writing and Testing a Web Service b. Implementing a Web Service Client ans : a. Writing a Web Service
The ASMX file shown in Figure 8.5 is a complete Web service. It implements two Web methods: Add and Subtract. Both take two integers as input and return an integer as well. Deploying the Web service is as simple as copying it to a directory on your Web server that is URL-addressable. If you put Calc.asmx in wwwroot, the Web services local URL is http://localhost/calc.asmx. Calc.asmx demonstrates several important principles of Web service programming using the .NET Framework: Web services are implemented in ASMX files. ASMX is a special file name extension registered to ASP.NET (specifically, to an ASP.NET HTTP handler) in Machine.config. ASMX files begin with @ WebService directives. At a minimum, the directive must contain a Class attribute identifying the class that makes up the Web service. Web service classes can be attributed with optional WebService attributes. The one in this example assigns the Web service a name and a description that show up in the HTML page generated when a user calls up Calc.asmx in his or her browser. The WebService attribute also supports a Namespace parameter that can be used to change the name of the XML namespace that scopes the Web services members.
b. Implementing a Web Service Client Here are the steps: 1. Use Wsdl.exe to create a proxy class for Calc.asmx. If you installed Calc.asmx in wwwroot, the proper command is
wsdl http://localhost/calc.asmx Wsdl.exe responds by creating a file named Calculator Web Service.cs. 2. Create a new text file named CalcClient.cs and enter the code . 3. Compile the CS files into a console application with the following command: csc CalcClient.cs "Calculator Web Service.cs" 4. Run CalcClient.exe. Q6. Describe the following with respect to Web site deployment in ASP.Net: a. Creating Application Pools (IIS 6.0)
b. Deploying ASP.NET Applications Deploying ASP.NET Applications in IIS 6.0 (IIS 6.0) Microsoft Windows Server 2003 includes support for ASP.NET applications and the Microsoft .NET Framework version 1.1 with the operating system installation. This chapter describes how to deploy ASP.NET applications on a newly installed server running Internet Information Services (IIS) 6.0. Version 1.1 of the .NET Framework is installed with Windows Server 2003. Most ASP.NET applications run without modification on version 1.1 of the .NET Framework