Asp Practical File
Asp Practical File
1
Aim: - Introduction Of .Net Framework.
Introduction:
.NET Framework (pronounced dot net) is a software framework developed by Microsoft
that runs primarily on Microsoft Windows. It includes a large library and provides
language interoperability (each language can use code written in other languages) across
several programming languages. Programs written for .NET Framework execute in a
software environment (as contrasted to hardware environment), known as the Common
Language Runtime (CLR), an application virtual machine that provides services such as
security, memory management, and exception handling. The class library and the CLR
together constitute .NET Framework.
.NET Framework's Base Class Library provides user interface, data access, database
connectivity, cryptography, web application development, numeric algorithms, and
network communications. Programmers produce software by combining their own source
code with .NET Framework and other libraries. .NET Framework is intended to be used
by most new applications created for the Windows platform. Microsoft also produces an
integrated development environment largely for .NET software called Visual Studio.
Microsoft started development of .NET Framework in the late 1990s, originally under the
name of Next Generation Windows Services (NGWS). By late 2000 the first beta
versions of .NET 1.0 were released.
Version 3.0 of .NET Framework is included with Windows Server 2008 and Windows
Vista. Version 3.5 is included with Windows 7 and Windows Server 2008 R2, and can
also be installed on Windows XP and Windows Server 2003. On 12 April 2010, .NET
Framework 4 was released alongside Visual Studio 2010.
.NET Framework family also includes two versions for mobile or embedded device use.
A reduced version of the framework, .NET Compact Framework, is available on
Windows CE platforms, including Windows Mobile devices such as smartphones.
Additionally, .NET Micro Framework is targeted at severely resource-constrained
devices.
Because computer systems commonly require interaction between newer and older
applications, .NET Framework provides means to access functionality
implemented in newer and older programs that execute outside .NET environment.
Access to COM components is provided in the System.Runtime.InteropServices
and System.EnterpriseServices namespaces of the framework; access to other
functionality is achieved using the P/Invoke feature.
Common Language Runtime engine
The Common Language Runtime (CLR) serves as the execution engine of .NET
Framework. All .NET programs execute under the supervision of the CLR,
guaranteeing certain properties and behaviors in the areas of memory
management, security, and exception handling.
Language independence
.NET Framework introduces a Common Type System, or CTS. The CTS
specification defines all possible datatypes and programming constructs supported
by the CLR and how they may or may not interact with each other conforming to
the Common Language Infrastructure (CLI) specification. Because of this
feature, .NET Framework supports the exchange of types and object instances
between libraries and applications written using any conforming .NET language.
Base Class Library
The Base Class Library (BCL), part of the Framework Class Library (FCL), is a
library of functionality available to all languages using .NET Framework. The
BCL provides classes that encapsulate a number of common functions, including
file reading and writing, graphic rendering, database interaction, XML document
manipulation, and so on. It consists of classes, interfaces of reusable types that
integrates with CLR(Common Language Runtime).
Simplified deployment
.NET Framework includes design features and tools which help manage the
installation of computer software to ensure it does not interfere with previously
installed software, and it conforms to security requirements.
Security
The design addresses some of the vulnerabilities, such as buffer overflows, which
have been exploited by malicious software. Additionally, .NET provides a
common security model for all applications.
3
Portability
While Microsoft has never implemented the full framework on any system except
Microsoft Windows, it has engineered the framework to be platform-agnostic and
cross-platform implementations are available for other operating systems
Microsoft submitted the specifications for the Common Language Infrastructure
(which includes the core class libraries, Common Type System, and the Common
Intermediate Language), the C# language and the C++/CLI language to both
ECMA and the ISO, making them available as official standards. This makes it
possible for third parties to create compatible implementations of the framework
and its languages on other platforms.
Architecture
.NET Framework includes a set of standard class libraries. The class library is organized
in a hierarchy of namespaces. Most of the built-in APIs are part of either System.* or
Microsoft.* namespaces. These class libraries implement a large number of common
functions, such as file reading and writing, graphic rendering, database interaction, and
XML document manipulation, among others. .NET class libraries are available to all CLI
compliant languages. .NET Framework class library is divided into two parts: the Base
Class Library and the Framework Class Library
The Base Class Library (BCL) includes a small subset of the entire class library and is the
core set of classes that serve as the basic API of the Common Language Runtime. The
classes in mscorlib.dll and some of the classes in System.dll and System.core.dll are
considered to be a part of the BCL. The BCL classes are available in both .NET
Framework as well as its alternative implementations including .NET Compact
Framework, Microsoft Silverlight and Mono.
The Framework Class Library (FCL) is a superset of the BCL classes and refers to the
entire class library that ships with .NET Framework. It includes an expanded set of
libraries, including Windows Forms, ADO.NET, ASP.NET, Language Integrated Query,
Windows Presentation Foundation, Windows Communication Foundation among others.
The FCL is much larger in scope than standard libraries for languages like C++, and
comparable in scope to the standard libraries of Java.
Memory management
.NET Framework CLR frees the developer from the burden of managing memory
(allocating and freeing up when done); it handles memory management itself by detecting
when memory can be safely freed. Instantiations of .NET types (objects) are allocated
from the managed heap; a pool of memory managed by the CLR. As long as there exists a
reference to an object, which might be either a direct reference to an object or via a graph
of objects, the object is considered to be in use. When there is no reference to an object,
and it cannot be reached or used, it becomes garbage, eligible for collection. .NET
Framework includes a garbage collector which runs periodically, on a separate thread
from the application's thread, that enumerates all the unusable objects and reclaims the
memory allocated to them.
.NET Garbage Collector (GC) is a non-deterministic, compacting, mark-and-sweep
garbage collector. The GC runs only when a certain amount of memory has been used or
there is enough pressure for memory on the system. Since it is not guaranteed when the
conditions to reclaim memory are reached, the GC runs are non-deterministic. Each .NET
6
application has a set of roots, which are pointers to objects on the managed heap
(managed objects). These include references to static objects and objects defined as local
variables or method parameters currently in scope, as well as objects referred to by CPU
registers. When the GC runs, it pauses the application, and for each object referred to in
the root, it recursively enumerates all the objects reachable from the root objects and
marks them as reachable. It uses CLI metadata and reflection to discover the objects
encapsulated by an object, and then recursively walk them. It then enumerates all the
objects on the heap (which were initially allocated contiguously) using reflection. All
objects not marked as reachable are garbage. This is the mark phase. Since the memory
held by garbage is not of any consequence, it is considered free space. However, this
leaves chunks of free space between objects which were initially contiguous. The objects
are then compacted together to make used memory contiguous again. Any reference to an
object invalidated by moving the object is updated by the GC to reflect the new location.
The application is resumed after the garbage collection is over.
The GC used by .NET Framework is also generational. Objects are assigned a
generation; newly created objects belong to Generation 0. The objects that survive a
garbage collection are tagged as Generation 1, and the Generation 1 objects that survive
another collection are Generation 2 objects. .NET Framework uses up to Generation 2
objects. Higher generation objects are garbage collected less frequently than lower
generation objects. This helps increase the efficiency of garbage collection, as older
objects tend to have a longer lifetime than newer objects. Thus, by eliminating older (and
thus more likely to survive a collection) objects from the scope of a collection run, fewer
objects need to be checked and compacted.
Alternative implementations
.NET Framework is the predominant implementation of .NET technologies. Other
implementations for parts of the framework exist. Although the runtime engine is
described by an ECMA/ISO specification, other implementations of it may be
encumbered by patent issues; ISO standards may include the disclaimer, "Attention is
drawn to the possibility that some of the elements of this document may be the subject of
patent rights. ISO shall not be held responsible for identifying any or all such patent
rights." It is more difficult to develop alternatives to the base class library (BCL), which
is not described by an open standard and may be subject to copyright restrictions.
Additionally, parts of the BCL have Windows-specific functionality and behavior, so
implementation on non-Windows platforms can be problematic.
Some alternative implementations of parts of the framework are listed here.
7
ECMA standard. Streaming SIMD Extensions have been available in x86 CPUs since the
introduction of the Pentium III. Some other architectures such as ARM and MIPS also
have SIMD extensions. In case the CPU lacks support for those extensions, the
instructions are simulated in software.
Security
Unobfuscated managed CIL bytecode can often be easier to reverse-engineer than native
code. One concern is over possible loss of trade secrets and the bypassing of license
control mechanisms. To mitigate this, Microsoft has included the Dotfuscator Community
Edition obfuscation tool within Visual Studio .NET since 2002. Third-party obfuscation
tools are also available from vendors such as vmware, V.i. Labs, Xenocode, Red Gate
Software. Method level encryption tools for .NET code are available from vendors such
as SafeNet.
.NET decompiler programs enable developers with no reverse-engineering skills to view
the source code behind unobfuscated .NET assemblies (DLL/EXE). In contrast,
applications built with Visual C++ are much harder to reverse-engineer and source code
is almost never produced successfully, mainly due to compiler optimizations and lack of
reflection.
Availability
While the standards that make up .NET are inherently cross-platform, Microsoft's full
implementation of .NET is supported only on Microsoft Window
Experiment No. 2
Aim:- Adding Two Numbers Using Windows Forms.
Form1.Designer.cs:
namespace SUM
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
10
this.BtnClose.Text = "close";
this.BtnClose.UseVisualStyleBackColor = true;
this.BtnClose.Click += new System.EventHandler(this.BtnClose_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.BtnClose);
this.Controls.Add(this.BtnSum);
this.Controls.Add(this.TxtResult);
this.Controls.Add(this.label3);
this.Controls.Add(this.TxtNum2);
this.Controls.Add(this.label2);
this.Controls.Add(this.TxtNum1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox TxtNum1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox TxtNum2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox TxtResult;
private System.Windows.Forms.Button BtnSum;
private System.Windows.Forms.Button BtnClose;
}
}
13
14
FORM.1(BUTTON CODING)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SUM
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BtnSum_Click(object sender, EventArgs e)
{
TxtResult.Text = (Convert.ToInt32(TxtNum1.Text)
Convert.ToInt32(TxtNum2.Text)).ToString();
}
15
Output Screen:-
16
Experiment No. 3
Aim: To Develop A Timed Math Quiz.
SOURCE CODE:
FORM1.DESIGNER.CS CODING:
namespace Math_Quiz
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
17
{
this.components = new System.ComponentModel.Container();
this.timeLabel = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.plusLeftLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.plusRightLabel = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.sum = new System.Windows.Forms.NumericUpDown();
this.difference = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.minusRightLabel = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.minusLeftLabel = new System.Windows.Forms.Label();
this.product = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label();
this.timesRightLabel = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.timesLeftLabel = new System.Windows.Forms.Label();
this.quotient = new System.Windows.Forms.NumericUpDown();
this.label10 = new System.Windows.Forms.Label();
this.dividedRightLabel = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.dividedLeftLabel = new System.Windows.Forms.Label();
this.startButton = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.sum)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.difference)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.product)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.quotient)).BeginInit();
this.SuspendLayout();
//
// timeLabel
//
this.timeLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.timeLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
18
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// plusRightLabel
//
this.plusRightLabel.Font = new System.Drawing.Font("Microsoft Sans Serif",
18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)
(0)));
this.plusRightLabel.Location = new System.Drawing.Point(154, 75);
this.plusRightLabel.Name = "plusRightLabel";
this.plusRightLabel.Size = new System.Drawing.Size(60, 50);
this.plusRightLabel.TabIndex = 4;
this.plusRightLabel.Text = "?";
this.plusRightLabel.TextAlign
=
System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(208, 75);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(60, 50);
this.label4.TabIndex = 5;
this.label4.Text = "=";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// sum
//
this.sum.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.sum.Location = new System.Drawing.Point(274, 84);
this.sum.Name = "sum";
this.sum.Size = new System.Drawing.Size(100, 35);
this.sum.TabIndex = 2;
this.sum.Enter += new System.EventHandler(this.answer_Enter);
//
// difference
20
//
this.difference.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.difference.Location = new System.Drawing.Point(274, 140);
this.difference.Name = "difference";
this.difference.Size = new System.Drawing.Size(100, 35);
this.difference.TabIndex = 3;
this.difference.Enter += new System.EventHandler(this.answer_Enter);
//
// label3
//
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(208, 131);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 50);
this.label3.TabIndex = 10;
this.label3.Text = "=";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// minusRightLabel
//
_ this.minusRightLabel.Font = new System.Drawing.Font("Microsoft Sans Serif",
18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)
(0)));
this.minusRightLabel.Location = new System.Drawing.Point(154, 131);
this.minusRightLabel.Name = "minusRightLabel";
this.minusRightLabel.Size = new System.Drawing.Size(60, 50);
this.minusRightLabel.TabIndex = 9;
this.minusRightLabel.Text = "?";
this.minusRightLabel.TextAlign
=
System.Drawing.ContentAlignment.MiddleCenter;
//
// label6
//
this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
21
this.label5.TabIndex = 15;
this.label5.Text = "=";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// timesRightLabel
//
this.timesRightLabel.Font = new System.Drawing.Font("Microsoft Sans Serif",
18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)
(0)));
this.timesRightLabel.Location = new System.Drawing.Point(154, 188);
this.timesRightLabel.Name = "timesRightLabel";
this.timesRightLabel.Size = new System.Drawing.Size(60, 50);
this.timesRightLabel.TabIndex = 14;
this.timesRightLabel.Text = "?";
this.timesRightLabel.TextAlign
=
System.Drawing.ContentAlignment.MiddleCenter;
//
// label8
//
this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label8.Location = new System.Drawing.Point(103, 188);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(60, 50);
this.label8.TabIndex = 13;
this.label8.Text = "";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// timesLeftLabel
//
this.timesLeftLabel.Font = new System.Drawing.Font("Microsoft Sans Serif",
18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)
(0)));
this.timesLeftLabel.Location = new System.Drawing.Point(52, 188);
this.timesLeftLabel.Name = "timesLeftLabel";
this.timesLeftLabel.Size = new System.Drawing.Size(60, 50);
this.timesLeftLabel.TabIndex = 12;
23
this.timesLeftLabel.Text = "?";
this.timesLeftLabel.TextAlign
System.Drawing.ContentAlignment.MiddleCenter;
//
// quotient
//
this.quotient.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.quotient.Location = new System.Drawing.Point(272, 252);
this.quotient.Name = "quotient";
this.quotient.Size = new System.Drawing.Size(100, 35);
this.quotient.TabIndex = 5;
this.quotient.Enter += new System.EventHandler(this.answer_Enter);
//
// label10
//
this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label10.Location = new System.Drawing.Point(206, 243);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(60, 50);
this.label10.TabIndex = 20;
this.label10.Text = "=";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// dividedRightLabel
//
this.dividedRightLabel.Font = new System.Drawing.Font("Microsoft Sans Serif",
18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)
(0)));
this.dividedRightLabel.Location = new System.Drawing.Point(152, 243);
this.dividedRightLabel.Name = "dividedRightLabel";
this.dividedRightLabel.Size = new System.Drawing.Size(60, 50);
this.dividedRightLabel.TabIndex = 19;
this.dividedRightLabel.Text = "?";
this.dividedRightLabel.TextAlign
=
System.Drawing.ContentAlignment.MiddleCenter;
24
//
// label12
//
this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label12.Location = new System.Drawing.Point(101, 243);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(60, 50);
this.label12.TabIndex = 18;
this.label12.Text = "";
this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// dividedLeftLabel
//
this.dividedLeftLabel.Font = new System.Drawing.Font("Microsoft Sans Serif",
18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)
(0)));
this.dividedLeftLabel.Location = new System.Drawing.Point(50, 243);
this.dividedLeftLabel.Name = "dividedLeftLabel";
this.dividedLeftLabel.Size = new System.Drawing.Size(60, 50);
this.dividedLeftLabel.TabIndex = 17;
this.dividedLeftLabel.Text = "?";
this.dividedLeftLabel.TextAlign
=
System.Drawing.ContentAlignment.MiddleCenter;
//
// startButton
//
this.startButton.AutoSize = true;
this.startButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.startButton.Location = new System.Drawing.Point(157, 315);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(127, 34);
this.startButton.TabIndex = 1;
this.startButton.Text = "Start the quiz";
this.startButton.UseVisualStyleBackColor = true;
this.startButton.Click += new System.EventHandler(this.startButton_Click);
25
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(484, 361);
this.Controls.Add(this.startButton);
this.Controls.Add(this.quotient);
this.Controls.Add(this.label10);
this.Controls.Add(this.dividedRightLabel);
this.Controls.Add(this.label12);
this.Controls.Add(this.dividedLeftLabel);
this.Controls.Add(this.product);
this.Controls.Add(this.label5);
this.Controls.Add(this.timesRightLabel);
this.Controls.Add(this.label8);
this.Controls.Add(this.timesLeftLabel);
this.Controls.Add(this.difference);
this.Controls.Add(this.label3);
this.Controls.Add(this.minusRightLabel);
this.Controls.Add(this.label6);
this.Controls.Add(this.minusLeftLabel);
this.Controls.Add(this.sum);
this.Controls.Add(this.label4);
this.Controls.Add(this.plusRightLabel);
this.Controls.Add(this.label2);
this.Controls.Add(this.plusLeftLabel);
this.Controls.Add(this.label1);
this.Controls.Add(this.timeLabel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.Name = "Form1";
26
}
}
FORM1.CS CODING:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Math_Quiz
{
public partial class Form1 : Form
{
// Create a Random object called randomizer
// to generate random numbers.
Random randomizer = new Random();
// These integer variables store the numbers
// for the addition problem.
int addend1;
int addend2;
// These integer variables store the numbers
// for the subtraction problem.
int minuend;
int subtrahend;
// These integer variables store the numbers
28
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Call the StartTheQuiz() method and enable
/// the Start button.
/// </summary>
private void startButton_Click(object sender, EventArgs e)
{
StartTheQuiz();
startButton.Enabled = false;
}
/// <summary>
/// Start the quiz by filling in all of the problem
/// values and starting the timer.
/// </summary>
public void StartTheQuiz()
29
{
// Fill in the addition problem.
// Generate two random numbers to add.
// Store the values in the variables 'addend1' and 'addend2'.
addend1 = randomizer.Next(51);
addend2 = randomizer.Next(51);
// Convert the two randomly generated numbers
// into strings so that they can be displayed
// in the label controls.
plusLeftLabel.Text = addend1.ToString();
plusRightLabel.Text = addend2.ToString();
// 'sum' is the name of the NumericUpDown control.
// This step makes sure its value is zero before
// adding any values to it.
sum.Value = 0;
// Fill in the subtraction problem.
minuend = randomizer.Next(1, 101);
subtrahend = randomizer.Next(1, minuend);
minusLeftLabel.Text = minuend.ToString();
minusRightLabel.Text = subtrahend.ToString();
difference.Value = 0;
// Fill in the multiplication problem.
multiplicand = randomizer.Next(2, 11);
multiplier = randomizer.Next(2, 11);
timesLeftLabel.Text = multiplicand.ToString();
timesRightLabel.Text = multiplier.ToString();
product.Value = 0;
// Fill in the division problem.
divisor = randomizer.Next(2, 11);
int temporaryQuotient = randomizer.Next(2, 11);
dividend = divisor * temporaryQuotient;
dividedLeftLabel.Text = dividend.ToString();
30
dividedRightLabel.Text = divisor.ToString();
quotient.Value = 0;
// Start the timer.
timeLeft = 30;
timeLabel.Text = "30 seconds";
timer1.Start();
}
/// <summary>
/// Time the quiz.
/// </summary>
private void timer1_Tick(object sender, EventArgs e)
{
if (CheckTheAnswer())
{
// If CheckTheAnswer() returns true, then the user
// got the answer right. Stop the timer
// and show a MessageBox.
timer1.Stop();
MessageBox.Show("You got all the answers right!",
"Congratulations!");
startButton.Enabled = true;
}
else if (timeLeft > 0)
{
// If CheckTheAnswer() return false, keep counting
// down. Decrease the time left by one second and
// display the new time left by updating the
// Time Left label.
timeLeft--;
timeLabel.Text = timeLeft + " seconds";
}
else
{
// If the user ran out of time, stop the timer, show
// a MessageBox, and fill in the answers.
31
timer1.Stop();
timeLabel.Text = "Time's up!";
MessageBox.Show("You didn't finish in time.", "Sorry!");
sum.Value = addend1 + addend2;
difference.Value = minuend - subtrahend;
product.Value = multiplicand * multiplier;
quotient.Value = dividend / divisor;
startButton.Enabled = true;
}
}
/// <summary>
/// Check the answers to see if the user got everything right.
/// </summary>
/// <returns>True if the answers are correct, false otherwise.</returns>
private bool CheckTheAnswer()
{
if ((addend1 + addend2 == sum.Value)
&& (minuend - subtrahend == difference.Value)
&& (multiplicand * multiplier == product.Value)
&& (dividend / divisor == quotient.Value))
return true;
else
return false;
}
/// <summary>
/// Modify the behavior of the NumericUpDown control
/// to make it easier to enter numeric values for
/// the quiz.
/// </summary>
private void answer_Enter(object sender, EventArgs e)
{
// Select the whole answer in the NumericUpDown control.
NumericUpDown answerBox = sender as NumericUpDown;
if (answerBox != null)
32
{
int lengthOfAnswer = answerBox.Value.ToString().Length;
answerBox.Select(0, lengthOfAnswer);
}
}
}
}
OUTPUT:
33
Experiment No. 4
34
Aim:- Write An Asp.Net Program To Display The Following Web Control:A Button
With Text Click Me. The Button Control Must Be In The Centre Of The Form
DESIGNER PAGE:
<html>
<head>
<title> Web Controls </title>
<center>
<asp:button id=b1" text=Click me runat=server />
</asp:button>
</center>
<asp:label id=L1" text=Hello runat=server />
</asp:label>
<asp:checkbox id=C1" runat=server/>
</asp:checkbox>
</head>
</html>
35
36
BUTTON CODING:
<html>
<head>
<title> ASP.NET </title>
<script language=c# runat=server>
void button1_Click(Object Sender,EventArgs E)
{
s1.InnerHtml=Welcome To Radiant;
}
</script>
</head>
<form id=f1 runat=server>
<body>
<center>
<asp:button id=b1" OnClick=button1_Click text=Click me runat=server
/>
</asp:button>
</center>
<span id=s1 runat=server />
</form>
</body>
</html>
37
Experiment No. 5
38
This technology forms a part of .NET Framework 3.0 (having been part of the framework
since version 1.0)
ADO.NET is conceptually divided into consumers and data providers. The consumers are
the applications that need access to the data, and the providers are the software
components that implement the interface and thereby provide the data to the consumer.
ADO.NET and Visual Studio
Functionality exists in Visual Studio IDE to create specialized subclasses of the DataSet
classes for a particular database schema, allowing convenient access to each field through
strongly typed properties. This helps catch more programming errors at compile-time and
makes the IDE's Intellisense feature more beneficial
39
Entity Framework
The ADO.NET Entity Framework is a set of data-access APIs for the Microsoft .NET
Framework, similar to the Java Persistence API, targeting the version of ADO.NET that
ships with .NET Framework 4.0. ADO.NET Entity Framework is included with .NET
Framework 4.0 and Visual Studio 2010, released in April 2010. An Entity Framework
Entity is an object which has a key representing the primary key of a logical datastore
entity. A conceptual Entity Data Model (Entity-relationship model) is mapped to a
datastore schema model. Using the Entity Data Model, the Entity Framework allows data
to be treated as entities independently of their underlying datastore representations.
Entity SQL, a SQL-like language, serves for querying the Entity Data Model (instead of
the underlying datastore). Similarly, LINQ extension LINQ to Entities provides typed
querying on the Entity Data Model. Entity SQL and LINQ to Entities queries are
converted internally into a Canonical Query Tree which is then converted into a query
understandable to the underlying database.
ADO.NET provides consistent access to data sources such as SQL Server and XML, and
to data sources exposed through OLE DB and ODBC. Data-sharing consumer
applications can use ADO.NET to connect to these data sources and retrieve, handle, and
update the data that they contain.
ADO.NET separates data access from data manipulation into discrete components that
can be used separately or in tandem. ADO.NET includes .NET Framework data providers
for connecting to a database, executing commands, and retrieving results. Those results
are either processed directly, placed in an ADO.NET DataSet object in order to be
exposed to the user in an ad hoc manner, combined with data from multiple sources, or
passed between tiers. The DataSet object can also be used independently of a .NET
Framework data provider to manage data local to the application or sourced from XML.
The ADO.NET classes are found in System.Data.dll, and are integrated with the XML
classes found in System.Xml.dll. For sample code that connects to a database, retrieves
data from it, and then displays that data in a console window
ADO.NET provides functionality to developers who write managed code similar to the
functionality provided to native component object model (COM) developers by ActiveX
Data Objects (ADO). We recommend that you use ADO.NET, not ADO, for accessing
data in your .NET applications.
40
ADO.NET provides the most direct method of data access within the .NET Framework.
For a higher-level abstraction that allows applications to work against a conceptual model
instead of the underlying storage model, see the ADO.NET Entity Framework.
Privacy
Statement:
The
System.Data.dll,
System.Data.Design.dll,
System.Data.OracleClient.dll,
System.Data.SqlXml.dll,
System.Data.Linq.dll,
System.Data.SqlServerCe.dll, and System.Data.DataSetExtensions.dll assemblies do not
distinguish between a user's private data and non-private data. These assemblies do not
collect, store, or transport any user's private data. However, third-party applications might
collect, store, or transport a user's private data using these assemblies
Experiment No. 6
Aim: Study Of C# Features.
41
42
{
length = 4.5;
width = 3.5;
}
public double GetArea()
{
return length * width;
}
public void Display()
{
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
class ExecuteRectangle
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.Acceptdetails();
r.Display();
Console.ReadLine();
}
}
}
When the above code is compiled and executed, it produces the following result:
Length: 4.5
Width: 3.5
Area: 15.75
The using Keyword
The first statement in any C# program is
44
using System;
The using keyword is used for including the namespaces in the program. A program can
include multiple using statements.
The class Keyword
The class keyword is used for declaring a class.
Comments in C#
Comments are used for explaining code. Compilers ignore the comment entries. The
multiline comments in C# programs start with /* and terminates with the characters */ as
shown below:
/* This program demonstrates
The basic syntax of C# programming
Language */
Single-line comments are indicated by the '//' symbol. For example,
}//end class Rectangle
Member Variables
Variables are attributes or data members of a class, used for storing data. In the preceding
program, the Rectangle class has two member variables named length and width.
Member Functions
Functions are set of statements that perform a specific task. The member functions of a
class are declared within the class. Our sample class Rectangle contains three member
functions: AcceptDetails, GetArea and Display.
Instantiating a Class
In the preceding program, the class ExecuteRectangle is used as a class, which contains
the Main() method and instantiates the Rectangle class.
Identifiers
45
An identifier is a name used to identify a class, variable, function, or any other userdefined item. The basic rules for naming classes in C# are as follows:
A name must begin with a letter that could be followed by a sequence of letters,
digits (0 - 9) or underscore. The first character in an identifier cannot be a digit.
It must not contain any embedded space or symbol like ? - +! @ # % ^ & * ( ) [ ] {
} . ; : " ' / and \. However, an underscore ( _ ) can be used.
It should not be a C# keyword
Experiment No. 7
Aim:- Study About Asp.Net
INTODUCTION:
ASP.NET is a server-side Web application framework designed for Web development to
produce dynamic Web pages. It was developed by Microsoft to allow programmers to
build dynamic web sites, web applications and web services. It was first released in
January 2002 with version 1.0 of the .NET Framework, and is the successor to
Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common
Language Runtime (CLR), allowing programmers to write ASP.NET code using any
supported .NET language. The ASP.NET SOAP extension framework allows ASP.NET
components to process SOAP messages.
Characteristics
ASP.NET Web pages, known officially as Web Forms, are the main building blocks for
application development. Web forms are contained in files with a ".aspx" extension; these
files typically contain static (X)HTML markup, as well as markup defining server-side
Web Controls and User Controls where the developers place all the rc contentfor the Web
page. Additionally, dynamic code which runs on the server can be placed in a page within
a block <% -- dynamic code -- %>, which is similar to other Web development
46
technologies such as PHP, JSP, and ASP. With ASP.NET Framework 2.0, Microsoft
introduced a new code-behind model which allows static text to remain on the .aspx page,
while dynamic code remains in an .aspx.vb or .aspx.cs or .aspx.fs file (depending on the
programming language used).
Directives
A directive is a special instruction on how ASP.NET should process the page.The most
common directive is <%@ Page %> which can specify many attributes used by the
ASP.NET page parser and compiler.
Examples
Inline code
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "---//W3C//DTD XHTML 1.0 //EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
// Assign the datetime to label control
lbl1.Text = DateTime.Now.ToLongTimeString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sample page</title>
</head>
<body>
<form id="form1" runat="server">
Code-behind solutions
<%@
Page
Language="C#"
CodeFile="SampleCodeBehind.aspx.cs"
Inherits="Website.SampleCodeBehind"
AutoEventWireup="true" %>
The above tag is placed at the beginning of the ASPX file. The CodeFile property of the
@ Page directive specifies the file (.cs or .vb or .fs) acting as the code-behind while the
Inherits property specifies the Class from which the Page is derived. In this example, the
47
@
Page
directive
is
included
in
SampleCodeBehind.aspx,
SampleCodeBehind.aspx.cs acts as the code-behind for this page:
then
into a dynamic link library (DLL) file. Such custom controls can be used across multiple
Web applications and Visual Studio projects.
Rendering technique
ASP.NET uses a visited composites rendering technique. During compilation, the
template (.aspx) file is compiled into initialization code which builds a control tree (the
composite) representing the original template. Literal text goes into instances of the
Literal control class, and server controls are represented by instances of a specific control
class. The initialization code is combined with user-written code (usually by the assembly
of multiple partial classes) and results in a class specific for the page. The page doubles
as the root of the control tree.
Actual requests for the page are processed through a number of steps. First, during the
initialization steps, an instance of the page class is created and the initialization code is
executed. This produces the initial control tree which is now typically manipulated by the
methods of the page in the following steps. As each node in the tree is a control
represented as an instance of a class, the code may change the tree structure as well as
manipulate the properties/methods of the individual nodes. Finally, during the rendering
step a visitor is used to visit every node in the tree, asking each node to render itself using
the methods of the visitor. The resulting HTML output is sent to the client.
After the request has been processed, the instance of the page class is discarded and with
it the entire control tree. This is a source of confusion among novice ASP.NET
programmers who rely on the class instance members that are lost with every page
request/response cycle.
State management
ASP.NET applications are hosted by a Web server and are accessed using the stateless
HTTP protocol. As such, if an application uses stateful interaction, it has to implement
state management on its own. ASP.NET provides various functions for state management.
Conceptually, Microsoft treats "state" as GUI state. Problems may arise if an application
needs to keep track of "data state"; for example, a finite-state machine which may be in a
transient state between requests (lazy evaluation) or which takes a long time to initialize.
State management in ASP.NET pages with authentication can make Web scraping
difficult or impossible.
49
Application
Application state is held by a collection of shared user-defined variables. These are set
and initialized when the Application_OnStart event fires on the loading of the first
instance of the application and are available until the last instance exits. Application state
variables are accessed using the Applications collection, which provides a wrapper for
the application state. Application state variables are identified by name.
Session state
Server-side session state is held by a collection of user-defined session variables that are
persistent during a user session. These variables, accessed using the Session collection,
are unique to each session instance. The variables can be set to be automatically
destroyed after a defined time of inactivity even if the session does not end. Client-side
user session is maintained by either a cookie or by encoding the session ID in the URL
itself.
ASP.NET supports three modes of persistence for server-side session variables:
In-process mode
The session variables are maintained within the ASP.NET process. This is the
fastest way; however, in this mode the variables are destroyed when the ASP.NET
process is recycled or shut down.
State server mode
ASP.NET runs a separate Windows service that maintains the state variables.
Because state management happens outside the ASP.NET process, and because the
ASP.NET engine accesses data using .NET Remoting, ASPState is slower than InProcess. This mode allows an ASP.NET application to be load-balanced and scaled
across multiple servers. Because the state management service runs independently
of ASP.NET, the session variables can persist across ASP.NET process shutdowns.
However, since session state server runs as one instance, it is still one point of
failure for session state. The session-state service cannot be load-balanced, and
there are restrictions on types that can be stored in a session variable.
SQL Server mode
State variables are stored in a database, allowing session variables to be persisted
across ASP.NET process shutdowns. The main advantage of this mode is that it
allows the application to balance load on a server cluster, sharing sessions between
servers. This is the slowest method of session state management in ASP.NET.
ASP.NET session state enables you to store and retrieve values for a user as the user
navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means
50
that a Web server treats each HTTP request for a page as an independent request. The
server retains no knowledge of variable values that were used during previous requests.
ASP.NET session state identifies requests from the same browser during a limited time
window as a session, and provides a way to persist variable values for the duration of that
session. By default, ASP.NET session state is enabled for all ASP.NET applications.
Alternatives to session state include the following:
Application state, which stores variables that can be accessed by all users of an
ASP.NET application.
Profile properties, which persists user values in a data store without expiring them.
ASP.NET caching, which stores values in memory that is available to all ASP.NET
applications.
View state, which persists values in a page.
Cookies.
The query string and fields on an HTML form that are available from an HTTP
request.
For a comparison of different state-management options, see ASP.NET State
Management Recommendations Session
View state
View state refers to the page-level state management mechanism, utilized by the HTML
pages emitted by ASP.NET applications to maintain the state of the Web form controls
and widgets. The state of the controls is encoded and sent to the server at every form
submission in a hidden field known as __VIEWSTATE. The server sends back the
variable so that, when the page is re-rendered, the controls render at their last state. At the
server side, the application may change the viewstate, if the processing requires a change
of state of any control. The states of individual controls are decoded at the server, and are
available for use in ASP.NET pages using the ViewState collection.
The main use for this is to preserve form information across postbacks. View state is
turned on by default and normally serializes the data in every control on the page
51
regardless of whether it is actually used during a postback. This behavior can (and
should) be modified, however, as View state can be disabled on a per-control, per-page,
or server-wide basis.
Developers need to be wary of storing sensitive or private information in the View state
of a page or control, as the base64 string containing the view state data can easily be deserialized. By default, View state does not encrypt the __VIEWSTATE value. Encryption
can be enabled on a server-wide (and server-specific) basis, allowing for a certain level of
security to be maintained.
Server-side caching
ASP.NET offers a "Cache" object that is shared across the application and can also be
used to store various objects. The "Cache" object holds the data only for a specified
amount of time and is automatically cleaned after the session time-limit elapses.
Other
Other means of state management that are supported by ASP.NET are cookies, caching,
and using the query string.
Template engine
When first released, ASP.NET lacked a template engine. Because the .NET Framework is
object-oriented and allows for inheritance, many developers would define a new base
class that inherits from "System.Web.UI.Page", write methods there that render HTML,
and then make the pages in their application inherit from this new class. While this allows
for common elements to be reused across a site, it adds complexity and mixes source
code with markup. Furthermore, this method can only be visually tested by running the
application not while designing it. Other developers have used include files and other
tricks to avoid having to implement the same navigation and other elements in every
page.
ASP.NET 2.0 introduced the concept of "master pages", which allow for template-based
page development. A Web application can have one or more master pages, which,
beginning with ASP.NET 2.0, can be nested. Master templates have place-holder controls,
called ContentPlaceHolders to denote where the dynamic content goes, as well as HTML
and JavaScript shared across child pages.
Child pages use those ContentPlaceHolder controls, which must be mapped to the placeholder of the master page that the content page is populating. The rest of the page is
defined by the shared parts of the master page, much like a mail merge in a word
52
processor. All markup and server controls in the content page must be placed within the
ContentPlaceHolder control.
When a request is made for a content page, ASP.NET merges the output of the content
page with the output of the master page, and sends the output to the user.
The master page remains fully accessible to the content page. This means that the content
page may still manipulate headers, change title, configure caching etc. If the master page
exposes public properties or methods (e.g. for setting copyright notices) the content page
can use these as well.
53
Experiment No.8
Aim: Write A Program To Display Welcome To Radiant In The Form When The
Click Button Is Clicked. The Form Title Must Be Asp.Net.
DESIGN CODING:
<html>
<head>
<Script language=c# runat=Server>
void Calculate(Object sender,EventArgs e)
{
if (Store.SelectedIndex > -1){
int i = Store.SelectedIndex;
Cost.Text = You have chosen + Store.SelectedItem.Value + and
its cost is Rs.;
if (i==0)
Cost.Text += 30;
else if (i==1)
Cost.Text += 32;
else if (i == 2)
Cost.Text += 28;
else
Cost.Text += 26;
}
}
void display(Object sender, EventArgs e)
{
int i = Store.SelectedIndex;
if (i==0)
{
Img.ImageUrl = Cola.gif;
Img.AlternateText = Cola;
}
54
else if (i==1)
{
Img.ImageUrl = Red_pop.gif;
Img.AlternateText = Red Pop;
}
else if (i == 2)
{
Img.ImageUrl = Lime.gif;
Img.AlternateText = Lime;
}
else
{
Img.ImageUrl = Purple_Rain.gif;
Img.AlternateText = Purple Rain;
}
}
</Script>
</head>
<body>
<form runat=server>
<asp:label id = label1 Text=Choose one of the items below
Font-Name=Verdana Font-Size=18pt runat=server />
<br><br>
<asp:listbox id=Store AutoPostBack=True width=200"
runat=server onSelectedIndexChanged=display>
<asp:listitem>Cola</asp:listitem>
<asp:listitem>Red Pop</asp:listitem>
<asp:listitem>Lime</asp:listitem>
<asp:listitem>Purple Rain</asp:listitem>
</asp:listbox>
<asp:Image ID=Img ImageUrl= AlternateText= runat=server />
<br><br>
<asp:button id=Find text=Find Cost OnClick=Calculate
runat=server/>
<br><br>
<asp:textbox id=Cost text=0" width=350 runat=server/>
ASP.NET
55
Output-
56
Experiment No. 9
Aim: Study About Xml (Extensible Markup Language)
Introduction:
Extensible Markup Language (XML) is a markup language that defines a set of rules
for encoding documents in a format that is both human-readable and machine-readable. It
is defined in the XML 1.0 Specification produced by the W3C, and several other related
specifications, all free open standards.
The design goals of XML emphasize simplicity, generality, and usability over the
Internet. It is a textual data format with strong support via Unicode for the languages of
the world. Although the design of XML focuses on documents, it is widely used for the
representation of arbitrary data structures, for example in web services.
Many application programming interfaces (APIs) have been developed to aid software
developers with processing XML data, and several schema systems exist to aid in the
definition of XML-based languages.
Key terminology
The material in this section is based on the XML Specification. This is not an exhaustive
list of all the constructs that appear in XML; it provides an introduction to the key
constructs most often encountered in day-to-day use.
(Unicode) character
By definition, an XML document is a string of characters. Almost every legal
Unicode character may appear in an XML document.
Processor and application
The processor analyzes the markup and passes structured information to an
application. The specification places requirements on what an XML processor
must do and not do, but the application is outside its scope. The processor (as the
specification calls it) is often referred to colloquially as an XML parser.
Markup and content
The characters making up an XML document are divided into markup and content,
which may be distinguished by the application of simple syntactic rules. Generally,
strings that constitute markup either begin with the character < and end with a >,
57
or they begin with the character & and end with a ;. Strings of characters that are
not markup are content. However, in a CDATA section, the delimiters <!
[CDATA[ and ]]> are classified as markup, while the text between them is
classified as content. In addition, whitespace before and after the outermost
element is classified as markup.
Tag
A markup construct that begins with < and ends with >. Tags come in three
flavors:
start-tags; for example: <section>
end-tags; for example: </section>
empty-element tags; for example: <line-break />
Element
A logical document component which either begins with a start-tag and ends with
a matching end-tag or consists only of an empty-element tag. The characters
between the start- and end-tags, if any, are the element's content, and may contain
markup, including other elements, which are called child elements. An example of
an element is <Greeting>Hello, world.</Greeting> Another is <line-break />.
Attribute
A markup construct consisting of a name/value pair that exists within a start-tag or
empty-element tag. In the example (below) the element img has two attributes, src
and alt:
<img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/>
Another example would be
<step number="3">Connect A to B.</step>
where the name of the attribute is "number" and the value is "3".
An XML attribute can only have a single value and each attribute can appear at most once
on each element. In the common situation where a list of multiple values is desired, this
must be done by encoding the list into a well-formed XML attribute with some format
beyond what XML defines itself. Usually this is either a comma or semi-colon delimited
list or, if the individual values are known not to contain spaces, a space-delimited list can
be used.
<div class="inner greeting-box" >Hello!</div>
58
where the attribute "class" has both the value "inner greeting-box", indicating the
CSS class names "inner" and "greeting-box".
XML declaration
XML documents may begin by declaring some information about themselves, as
in the following example:
<?xml version="1.0" encoding="UTF-8"?>
Characters and escaping
XML documents consist entirely of characters from the Unicode repertoire. Except for a
small number of specifically excluded control characters, any character defined by
Unicode may appear within the content of an XML document.
XML includes facilities for identifying the encoding of the Unicode characters that make
up the document, and for expressing characters that, for one reason or another, cannot be
used directly.
Valid characters
Unicode code points in the following ranges are valid in XML 1.0 documents:
U+0009, U+000A, U+000D: these are the only C0 controls accepted in XML 1.0;
U+0020U+D7FF, U+E000U+FFFD: this excludes some (not all) non-characters
in the BMP (all surrogates, U+FFFE and U+FFFF are forbidden);
U+10000U+10FFFF: this includes all code points in supplementary planes,
including non-characters.
XML 1.1 extends the set of allowed characters to include all the above, plus the
remaining characters in the range U+0001U+001F. At the same time, however, it
restricts the use of C0 and C1 control characters other than U+0009, U+000A, U+000D,
and U+0085 by requiring them to be written in escaped form (for example U+0001 must
be written as  or its equivalent). In the case of C1 characters, this restriction is a
backwards incompatibility; it was introduced to allow common encoding errors to be
detected.
The code point U+0000 is the only character that is not permitted in any XML 1.0 or 1.1
document.
59
Encoding detection
The Unicode character set can be encoded into bytes for storage or transmission in a
variety of different ways, called "encodings". Unicode itself defines encodings that cover
the entire repertoire; well-known ones include UTF-8 and UTF-16. There are many other
text encodings that predate Unicode, such as ASCII and ISO/IEC 8859; their character
repertoires in almost every case are subsets of the Unicode character set.
XML allows the use of any of the Unicode-defined encodings, and any other encodings
whose characters also appear in Unicode. XML also provides a mechanism whereby an
XML processor can reliably, without any prior knowledge, determine which encoding is
being used. Encodings other than UTF-8 and UTF-16 will not necessarily be recognized
by every XML parser.
Escaping
XML provides escape facilities for including characters which are problematic to include
directly. For example:
The characters "<" and "&" are key syntax markers and may never appear in
content outside a CDATA section.
Some character encodings support only a subset of Unicode. For example, it is
legal to encode an XML document in ASCII, but ASCII lacks code points for
Unicode characters such as "".
It might not be possible to type the character on the author's machine.
Some characters have glyphs that cannot be visually distinguished from other
characters: There are five predefined entities:
< represents "<"
> represents ">"
& represents "&"
' represents '
" represents "
60
All permitted Unicode characters may be represented with a numeric character reference.
Consider the Chinese character " ", whose numeric code in Unicode is hexadecimal
4E2D, or decimal 20,013. A user whose keyboard offers no method for entering this
character could still insert it in an XML document encoded either as 中 or
中. Similarly, the string "I <3 Jrg" could be encoded for inclusion in an XML
document as "I <3 Jörg".
"�" is not permitted, however, because the null character is one of the control
characters excluded from XML, even when using a numeric character reference. An
alternative encoding mechanism such as Base64 is needed to represent such characters.
Comments
Comments may appear anywhere in a document outside other markup. Comments cannot
appear before the XML declaration. Comments start with "<!--" and end with "-->". The
string "--" (double-hyphen) is not allowed inside comments; this means comments cannot
be nested. The ampersand has no special significance within comments, so entity and
character references are not recognized as such, and there is no way to represent
characters outside the character set of the document encoding.
Well-formedness and error-handling
The XML specification defines an XML document as a well-formed text meaning that
it satisfies a list of syntax rules provided in the specification. Some key points in the
fairly lengthy list include:
The document contains only properly encoded legal Unicode characters
None of the special syntax characters such as < and & appear except when
performing their markup-delineation roles
The begin, end, and empty-element tags that delimit the elements are correctly
nested, with none missing and none overlapping
The element tags are case-sensitive; the beginning and end tags must match
exactly. Tag names cannot contain any of the characters !"#$%&'()*+,/;<=>?
@[\]^`{|}~, nor a space character, and cannot start with -, ., or a numeric digit.
A single "root" element contains all the other elements
61
The definition of an XML document excludes texts that contain violations of wellformedness rules; they are simply not XML. An XML processor that encounters such a
violation is required to report such errors and to cease normal processing. This policy,
occasionally referred to as draconian, stands in notable contrast to the behavior of
programs that process HTML, which are designed to produce a reasonable result even in
the presence of severe markup errors. XML's policy in this area has been criticized as a
violation of Postel's law ("Be conservative in what you send; be liberal in what you
accept").
The XML specification defines a valid XML document as a well-formed XML
document which also conforms to the rules of a Document Type Definition (DTD). By
extension, the term can also refer to documents that conform to rules in other schema
languages, such as XML Schema (XSD). This term should not be confused with a wellformed XML document, which is defined as an XML document that has correct XML
syntax according to W3C standards.
Schemas and validation
In addition to being well-formed, an XML document may be valid. This means that it
contains a reference to a Document Type Definition (DTD), and that its elements and
attributes are declared in that DTD and follow the grammatical rules for them that the
DTD specifies.
XML processors are classified as validating or non-validating depending on whether or
not they check XML documents for validity. A processor that discovers a validity error
must be able to report it, but may continue normal processing.
A DTD is an example of a schema or grammar. Since the initial publication of XML 1.0,
there has been substantial work in the area of schema languages for XML. Such schema
languages typically constrain the set of elements that may be used in a document, which
attributes may be applied to them, the order in which they may appear, and the allowable
parent/child relationships.
Document Type Definition
The oldest schema language for XML is the Document Type Definition (DTD), inherited
from SGML.
DTDs have the following benefits:
DTD support is ubiquitous due to its inclusion in the XML 1.0 standard.
62
languages. They use a rich datatyping system and allow for more detailed constraints on
an XML document's logical structure. XSDs also use an XML-based format, which
makes it possible to use ordinary XML tools to help process them.
Related specifications
A cluster of specifications closely related to XML have been developed, starting soon
after the initial publication of XML 1.0. It is frequently the case that the term "XML" is
used to refer to XML together with one or more of these other technologies which have
come to be seen as part of the XML core.
XML Namespaces enable the same document to contain XML elements and
attributes taken from different vocabularies, without any naming collisions
occurring. Although XML Namespaces are not part of the XML specification
itself, virtually all XML software also supports XML Namespaces.
XML Base defines the xml:base attribute, which may be used to set the base for
resolution of relative URI references within the scope of a single XML element.
The XML Information Set or XML infoset describes an abstract data model for
XML documents in terms of information items. The infoset is commonly used in
the specifications of XML languages, for convenience in describing constraints on
the XML constructs those languages allow.
xml:id Version 1.0 asserts that an attribute named xml:id functions as an "ID
attribute" in the sense used in a DTD.
XPath defines a syntax named XPath expressions which identifies one or more of
the internal components (elements, attributes, and so on) included in an XML
document. XPath is widely used in other core-XML specifications and in
programming libraries for accessing XML-encoded data.
XSLT is a language with an XML-based syntax that is used to transform XML
documents into other XML documents, HTML, or other, unstructured formats
such as plain text or RTF. XSLT is very tightly coupled with XPath, which it uses
to address components of the input XML document, mainly elements and
attributes.
64
XSLT is designed for declarative description of XML document transformations, and has
been widely implemented both in server-side packages and Web browsers. XQuery
overlaps XSLT in its functionality, but is designed more for searching of large XML
databases.
Experiment No. 10
Aim:
Write a JavaScript program to display a calendar with the following specifications:
The width of the border is 10 units
The border is set to inset style
The cellpadding is set to 1
The cellspacing is set to 4
The height of the calendar is 300px
The width of the calendar is 500px
The Days are displayed as Sun, Mon etc.
The first day of the week is Saturday
The days are displayed in brown color
The names of the next and previous months are displayed as full months
The next and previous months are displayed in white color
The days of other months are displayed in gray color
The SelectionMode is set to DayWeekMonth
The background color of the selected day(s) is lightblue
The background color of the selector tab is lightgreen and its text is in black
66
The current day is set to blue color and its text is made bold
The background color of the title is green, its text is white and it is made bold
SOLUTION:
<form runat = server>
<asp:Calendar id=Calendar2 runat=server
borderwidth=10
borderstyle=inset
cellpadding=1
cellspacing=4
DayNameFormat=Short
Firstdayofweek=saturday
Forecolor=brown
Height=300px
Width=500px
NextPrevFormat=fullmonth
NextPrevStyle-ForeColor=white
OtherMonthDayStyle-ForeColor=gray
SelectionMode=DayWeekMonth
SelectedDayStyle-BackColor=lightblue
67
SelectorStyle-BackColor=lightgreen
SelectorStyle-ForeColor=black
TodayDayStyle-Font-Bold=True
TodayDayStyle-ForeColor=blue
TitleStyle-BackColor=green
TitleStyle-ForeColor=white
TitleStyle-Font-Bold=True
/>
</form>
Output-
68
69