UGC NET STUDY MATERIALS

Dot net technology (.NET)

August 2010
Master of Computer Application (MCA) – Semester 5
MC0081 – .(DOT) Net Technologies – 4 Credits
(Book ID: B0974)
Assignment Set – 1 (40 Marks)

Answer all Questions Each question carries TEN marks
1. Explain the following with respect to Dot Net Technology:
A) Features of .Net platform
The .NET Framework is an integral Windows component that supports building and running the next generation of applications and XML Web services. The .NET Framework is designed to fulfill the following objectives:

To provide a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.

To provide a code-execution environment that minimizes software deployment and versioning conflicts.

To provide a code-execution environment that promotes safe execution of code, including code created by an unknown or semi-trusted third party.

To provide a code-execution environment that eliminates the performance problems of scripted or interpreted environments.

To make the developer experience consistency across widely varying types of applications, such as Windows-based applications and Web-based applications.

To build all communication on industry standards to ensure that code based on the .NET Framework can integrate with any other code.
The .NET Framework has two main components: the common language runtime and the .NET Framework class library. The common language runtime is the foundation of the .NET Framework. You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness. In fact, the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code. The class library, the other main component of the .NET Framework, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services. The .NET Framework can be hosted by unmanaged components that load the common language runtime into their processes and initiate the execution of managed code, thereby creating a software environment that can exploit both managed and unmanaged features. The .NET Framework not only provides several runtime hosts, but also supports the development of third-party runtime hosts. For example, ASP.NET hosts the runtime to provide a scalable, server-side environment for managed code. ASP.NET works directly with the runtime to enable ASP.NET applications and XML Web services, both of which are discussed later in this topic.
Internet Explorer is an example of an unmanaged application that hosts the runtime (in the form of a MIME type extension). Using Internet Explorer to host the runtime enables you to embed managed components or Windows Forms controls in HTML documents. Hosting the runtime in this way makes managed mobile code (similar to Microsoft® ActiveX® controls) possible, but with significant improvements that only managed code can offer, such as semi-trusted execution and isolated file storage. The figure shows the relationship of the common language runtime and the class library to your applications and to the overall system. It also shows how managed code operates within a larger architecture.


B) Assemblies in .Net: 


The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third-party components can integrate seamlessly with classes in the .NET Framework.
For example, the .NET Framework collection classes implement a set of interfaces that you can use to develop your own collection classes. Your collection classes will blend seamlessly with the classes in the .NET Framework. As you would expect from an object-oriented class library, the .NET Framework types enable you to accomplish a range of common programming tasks, including tasks such as string management, data collection, database connectivity, and file access. In addition to these common tasks, the class library includes types that support a variety of specialized development scenarios. For example, you can use the .NET Framework to develop the following types of applications and services:
  • Console applications.
  • Windows GUI applications (Windows Forms).
  • Windows Presentation Foundation (WPF) applications.
  • ASP.NET applications.
  • Web services.
  • Windows services.
  • Service-oriented applications using Windows Communication Foundation (WCF).
  • Workflow-enabled applications using Windows Workflow Foundation (WF).

For example, the Windows Forms classes are a comprehensive set of reusable types that vastly simplify Windows GUI development. If you write an ASP.NET Web Form application, you can use the Web Forms classes.

2. Explain the following with respect to C# programming:
A) Properties and Indexes:

Properties are members that provide a flexible mechanism to read, write, or compute the values of private fields. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.
Properties Overview:
• Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code.
• A get property accessor is used to return the property value, and a set accessor is used to assign a new value. These accessors can have different access levels.

• The value keyword is used to define the value being assigned by the set indexer.

• properties that do not implement a set method are read only.

Using Properties:

Properties combine aspects of both fields and methods. To the user of an object, a property appears to be a field, accessing the property requires the same syntax. To the implementer of a class, a property is one or two code blocks, representing a get accessor and/or a set accessor. The code block for the get accessor is executed when the property is read; the code block for the set accessor is executed when the property is assigned a new value. A property without a set accessor is considered read-only. A property without a get accessor is considered write-only. A property that has both accessors is read-write. Unlike fields, properties are not classified as variables. Therefore, you cannot pass a property as a ref (C# Reference) or out (C# Reference) parameter. Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields. Properties are declared in the class block by specifying the access level of the field, followed by the type of the property, followed by the name of the property, and followed by a code block that declares a get-accessor and/or a set accessor.
The get Accessor: The body of the get accessor resembles that of a method. It must return a value of the property type. The execution of the get accessor is equivalent to reading the value of the field. For example, when you are returning the private variable from the get accessor and optimizations are enabled, the call to the get accessor method is in lined by the compiler so there is no method-call overhead. However, a virtual get accessor method cannot be in lined because the compiler does not know at compile-time which method may actually be called at run time.

Set Accessor: 

The set accessor resembles a method whose return type is void. It uses an implicit parameter called value, whose type is the type of the property.

B) Delegates and Events
An event is a message sent by an object to signal the occurrence of an action. The action could be caused by user interaction, such as a mouse click, or it could be triggered by some other program logic. The object that raises the event is called the event sender. The object that captures the event and responds to it is called the event receiver. In event communication, the event sender class does not know which object or method will receive (handle) the events it raises. What is needed is an intermediary (or pointer-like mechanism) between the source and the receiver. The .NET Framework defines a special type (Delegate) that provides the functionality of a function pointer.
A delegate is a class that can hold a reference to a method. Unlike other classes, a delegate class has a signature, and it can hold references only to methods that match its signature. A delegate is thus equivalent to a type-safe function pointer or a callback. While delegates have other uses, the discussion here focuses on the event handling functionality of delegates. A delegate declaration is sufficient to define a delegate class. The declaration supplies the signature of the delegate, and the common language runtime
provides the implementation. The following example shows an event delegate declaration.


Events:
Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.
In a typical C# Windows Forms or Web application, you subscribe to events raised by controls such as buttons and list boxes. You can use the Visual C# integrated development environment (IDE) to browse the events that a control publishes and select the ones that you want to handle. The IDE automatically adds an empty event handler method and the code to subscribe to the event.
Events Overview :
Events have the following properties:

• The publisher determines when an event is raised; the subscribers determine what action is taken in response to the event.
• An event can have multiple subscribers. A subscriber can handle multiple events from multiple publishers.

• Events that have no subscribers are never called.

• Events are typically used to signal user actions such as button clicks or menu selections in graphical user interfaces.

• When an event has multiple subscribers, the event handlers are invoked synchronously when an event is raised. To invoke events asynchronously, see Calling Synchronous Methods Asynchronously.

• Events can be used to synchronize threads.

• In the .NET Framework class library, events are based on the EventHandler delegate and the EventArgs base class.


3. Explain the following with respect to ASP.Net:
A) Master Pages:
Master Pages – The Master Pages feature provides the ability to define common structure and interface elements for your site, such as a page header, footer, or navigation bar, in a common location called a "master page", to be shared by many pages in your site. This improves the maintainability of your site and avoids unnecessary duplication of code for shared site structure or behavior.
Just as Themes and Skins allow you to factor out style definitions from your page code and maintain them in a common file, Master Pages do the same for page layout. A Master Page is a page that contains markup and controls that should be shared across multiple pages in your site. For example, if all of your pages should have the same header and footer banners or the same navigation menu, you could define this in a Master Page once, and then all pages associated to this Master Page would inherit those common elements. The advantage of defining the header, footer, and navigation in a Master Page is that these elements need only be defined once, instead of multiple times in duplicate code across the pages in your site. The Master Pages are an easy way to provide a template that can be used by any number of ASP.NET pages in your application. In working with Master Pages, the developer creates a Master File that is the template referenced by a subpage or Content Page. Master Pages use a .master file extension, whereas content pages use the .aspx file extension you are used to; but content pages are declared as such within the file’s page directive.
Master and Content Pages :
Defining a Master Page is just like defining a normal page. Master Pages can contain markup, controls, or code, or any combination of these elements. However, a Master Page can contain a special type of control, called a ContentPlaceHolder control. A ContentPlaceHolder defines a region of the master page rendering that can be substituted with content from a page associated to the master. A ContentPlaceHolder can also contain default content, just in case the derive page does not need to override this content. The syntax of a ContentPlaceHolder control is given below:
<%-- ContentPlaceHolder control --%>

<%-- ContentPlaceHolder with default content --%>


To differentiate a Master Page from a normal page, a Master Page is saved under the .master file extension. A page can derive from a Master Page by defining a MasterPageFile attribute on its Page directive, as demonstrated below. A page that is associated to a Master Page is called a Content Page.
<%@ Page MasterPageFile="Site.master" %>
A Content Page can declare Content controls that specifically override content placeholder sections in the Master Page. A Content control is associated to a particular ContentPlaceHolder control through its ContentPlaceHolderID property. A Content Page may only contain markup and controls inside Content controls; it cannot have any top-level content of its own. It can, however, have directives or server-side code.
<%@ Page MasterPageFile="Site.master" %>

With sunshine, water, and careful tending, roses will bloom several times in a season.
B) Themes & Control Skins
Creating Themes:
Themes and Skins: The Themes and Skins feature of ASP.NET allows you to factor style and layout information into a separate group of files, collectively called a Theme. A Theme can then be applied to any site to affect the look and feel of pages and controls within the site. Style changes to a site can then be easily maintained by making changes to the Theme, without having to edit the individual pages in your site. Themes can also be shared with other developers. When you build a web application, it usually has a similar look-and-feel across all its pages. Not too many applications are designed with each page dramatically different from each other. In general, your applications use similar fonts, colors, and server control styles across all the pages within the application. You can apply these common styles individually to each and every server control or objects on each page, or you can use a capability provided by ASP.NET to centrally specify these styles. All pages or parts of pages in the application can then access them. Themes are the text-based style definitions in ASP.NET. You create .skin files in the Theme folder. A .skin file can contain one or more control skins for one or more control types. You can define skins in a separate file for each control or define all the skins for a theme in a single file.
There are two types of control skins, default skins and named skins:
A Default Skin automatically applies to all controls of the same type when a theme is applied to a page. A Control Skin is a default skin if it does not have a SkinID attribute. For example, if you create a default skin for a Calendar control, the control skin applies to all Calendar controls on pages that use the theme. (Default skins are matched exactly by control type, so that a Button control skin applies to all Button controls, but not to LinkButton controls or to controls that derive from the Button object.) A Named Skin is a control skin with a SkinID property set. Named skins do not automatically apply to controls by type. Instead, you explicitly apply a named skin to a control by setting the control's SkinID property. Creating named skins allows you to set different skins for different instances of the same control in an application.
 

Cascading Style Sheets:
A theme can also include a cascading style sheet (.css file). When you put a .css file in the theme folder, the style sheet is applied automatically as part of the theme. You define a style sheet using the file name extension .css in the theme folder. The following are the uses of ASP.NET Themes:

They enable you to define visual styles for your Web Pages
They also allow you to apply styles, graphics
They allow you to apply the CSS files themselves to the pages of an application
They can be applied at the application, page, or server control level. STLNET



This simple page shows some default server controls, but which you can change with one of these new ASP.NET themes. You can instantly change the appearance of this page without changing the style of each server control on the page. From within the Page directive, you simply apply an ASP.NET theme that you have either built or downloaded from the Internet: <%@ Page Language = “VB” Theme = “SmokeAndGlass” %> Adding the Them attribute changes the appearance of everything on the page that is defined in an example SmokeAndGlass theme file. If you have multiple pages, you do not have to think about applying styles to everything you do as you build because the styles are already defined centrally for you.
 

Applying a Theme to an Entire Application:
You can apply a Theme to your entire application using the web.config file.
By specifying the Theme in your web.config file, you need not define the theme again in the Page directive of your ASP.NET pages. This theme is applied automatically to each and every page within your application. In order to apply the theme to only a specific part of an application, make use of the element to specify the areas of the application for which the theme should be applied.
Removing Themes from the Server Controls:
Some times you want an alternative to the theme that has already been defined. As an example, to change the text box server control that you have been already working with by making its background black and using white text:

To apply a theme to your ASP.NET page but not to the Textbox control, use the EnableTheming property of the Textbox Server Control:

To turn off the theming property for multiple controls within a page, consider using the Panel Control (or any Container Control) to encapsulate a collection of controls and then set the EnableTheming attribute of the Control Panel to false. This disables the theming for each and every control within the panel.
Creation of User-Defined Themes:
Users can define their own themes to the pages they would create within an application. These themes created can be applied at the following levels within an application:

  • Application Level
  • Page Level
  • Server Control Level
Themes are a way of applying a consistent look and feel across entire application. To create your own themes at first, you have to create a proper folder structure in your application.
Step1: Right click the project and add a new folder
Step 2: Name the folder appropriately (for example: App_Themes)
Step 3: You can also create this folder by right – clicking on your project in Visual Studio and selecting Add ASP.NET Folder Theme.


4. Describe the theory of Server Controls in ASP.Net
 

ASP.NET Server Controls:
ASP.NET Web Server controls are objects on ASP.NET Web pages that run when the page is requested and render markup to a browser. Many Web server controls are similar to familiar HTML elements, such as buttons and text boxes. Other controls encompass complex behavior, such as calendar controls, and controls that manage data connections. ASP.NET Web Server Controls Overview When you create ASP.NET Web pages, you can use these types of controls:

HTML Server Controls: They are the HTML elements exposed to the server so you can program them. HTML server controls expose an object model that maps very closely to the HTML elements that they render.

Web Server Controls: They are the Controls with more built-in features than HTML server controls. Web server controls include not only form controls such as buttons and text boxes, but also special-
purpose controls such as a calendar, menus, and a tree view control. Web server controls are more abstract than HTML server controls in that their object model does not necessarily reflect HTML syntax.

Validation Controls: They are the Controls that incorporate logic to enable you to what users enter for input controls such as the TextBox control. Validation controls enable you to check for a required field, to test against a specific value or pattern of characters, to verify that a value lies within a range, and so on.

User Controls: They are the Controls that you create as ASP.NET Web pages. You can embed ASP.NET user controls in other ASP.NET Web pages, which is an easy way to create toolbars and other reusable elements.

HTML Server Controls:

 
HTML server controls are HTML elements (or elements in other supported markup, such as XHTML) containing attributes that make them programmable in server code. By default, HTML elements on an ASP.NET Web page are not available to the server. Instead, they are treated as opaque text and passed through to the browser. However, by converting HTML elements to HTML server controls, you expose them as elements you can program on the server. The object model for HTML server controls maps closely to that of the corresponding elements. For example, HTML attributes are exposed in HTML server controls as properties.
Any HTML element on a page can be converted to an HTML server control by adding the attribute runat="server". During parsing, the ASP.NET page framework creates instances of all elements containing the runat="server" attribute. If you want to refer to the control as a member within your code, you should also assign an id attribute to the control.
The page framework provides predefined HTML server controls for the HTML elements most commonly used dynamically on a page: the form element, the input elements (text box, check box, Submit button), the select element, and so on. These predefined HTML server controls share the basic properties of the generic control, and in addition, each control typically provides its own set of properties and its own event.

HTML Server Control Features:

• An object model that you can program against on the server using familiar object-oriented techniques. Each server control exposes properties that enable you to manipulate the control's markup attributes programmatically in server code.

• A set of events for which you can write event handlers in much the same way you would in a client-based form, except that the event is handled in server code.

• The ability to handle events in client script.

• Automatic maintenance of the control's state. When the page makes a round trip to the server, the values that the user entered into HTML server controls are automatically maintained and sent back to the browser.

• Interaction with ASP.NET validation controls so you can verify that a user has entered appropriate information into a control.

• Data binding to one or more properties of the control.

• Support for styles if the ASP.NET Web page is displayed in a browser that supports cascading style sheets.

• Pass-through of custom attributes. You can add any attributes you need to an HTML server control and the page framework will render them without any change in functionality. This enables you to add browser-specific attributes to your controls.

Working with Web Server Controls:

 
Web server controls are a second set of controls designed with a different emphasis. They do not necessarily map one-to-one to HTML server controls. Instead, they are defined as abstract controls in which the actual markup rendered by the control can be quite different from the model that you program against. For example, a RadioButtonList Web server control might be rendered in a table or as inline text with other markup. Web server controls include traditional form controls such as buttons and text boxes as well as complex controls such as tables. They also include controls that provide commonly used form functionality such as displaying data in a grid, choosing dates, displaying menus, and so on. The controls use syntax such as the following:

The attributes in this case are not those of HTML elements. Instead, they are properties of the Web control. When the ASP.NET Web page runs, the Web server control is rendered on the page using appropriate markup, which often depends not only on the browser type but also on settings that you have made for the control. For example, a TextBox control might render as an input tag or a textarea tag, depending on its properties. You add controls to an ASP.NET Web page much the same way you add any HTML element. You can either use a visual designer and add a control from the toolbox, or you can type the element representing the control into the page's markup.
To add a Web server control using the designer:

1. Switch to Design view.
2. From the Standard tab of the Toolbox, drag the control onto the page. A glyph () appears on the control in Design view to indicate that it is a server-based control.


To add a control to an ASP.NET Web page programmatically

1. Create an instance of the control and set its properties, as shown in the following example:
C# Code
Label myLabel = new Label();
myLabel.Text = "Sample Label";

2. Add the new control to the Controls collection of a container already on the page, as shown in the following example:
C# Code
Panel Panel1= new Panel();
Panel1.Controls.Add(myLabel);

How to: Set ASP.NET Web Server Control Properties:
Setting a control's properties defines its appearance and behavior. This topic addresses how to set control properties declaratively.
To set server controls properties:
In the ASP.NET Web page, set the attribute of the control declaration corresponding to the property you want.
The exact attribute you set depends on the control and the property. For information about the properties for a specific control, search for the name of the control class (for example, "Button class (System.Web.UI.WebControls)" in the Help index.

Setting Server Control Properties Based on Simple Values or Enumerations :
If a Web server control property's data type is a primitive type, such as a String, Boolean, or numeric type, you can set the property value by simply assigning it to the property. Similarly, if the property's values are defined in an enumeration class, you can simply assign the enumeration to the property.
To set a property value based on simple values

Assign the value as a literal or variable, as in the following example:
C# Syntax
Label1.Text = "Hello";
DataGrid1.PageSize = 5;







August 2010
Master of Computer Application (MCA) – Semester 5
MC0081 – .(DOT) Net Technologies – 4 Credits
(Book ID: B0974)
Assignment Set – 2 (40 Marks)

Answer all Questions Each question carries TEN marks

1. Describe the following with respect to ASP.Net:
A) State Management
B) Cookies

2. Describe the theory of the following concepts in ADO.Net:
A) Connection Strings
B) Connection String Builders

3. Describe the following in the context of Web Services:
A) Web Services and code behind
B) Web Service clients and proxies

4. Describe the theory of creating application pools in IIS 6.0.

Popular Posts

Recent Posts