User Control

Validation Controls

Before saving the data entered by the user into a webform, we will have to validate the data. A web form is form which is used to accept data from the user in a web application. We will how to use the validation in a webform to perform the validations against the data entered by the user. Validation controls are controls which help us to perform different validations on the data entered in controls like Textbox, Listbox and radiobutton.

Strings

Strings are supported by the .NET String class. The String data type can represent a series of characters and can contain approximately up to 2 billion Unicode characters. There are many built-in functions in the String class. Some .NET Framework function are also built into the String class. Some common String functions are discussed below:

  • LCase: Converts a string to lower case
  • UCase:Converts a string to uppercase
  • Len: Calculates the number of characters in the string
  • LTrim:Omits spaces that appear on the left-side of the string
  • RTrim:Omits spaces that appear on the Right-side of the string
  • Trim: Omits both leading and trailing spaces
  • Clone: Clones a string
  • Concat:Joins two strings
  • Space: Used to create a string with spaces
  • Left: Takes two arguments and return a string that consists of the left most characters of the string sent
  • Right: Takes two arguments and return a string that consists of the Right most characters of the string sent
  • Instr: Searches and return a shorter string within a long string
  • Replace:Searches for a small string in a long string and replace it with the specified string.

Arrays in ASP.NET

Arrays allows you to store a series of value that have the same data type. Each individual value in the array is accessed using one or more index number. It's often convenient to picture arrays as list of data (if the array has more then one dimension) or grids of data (if the array has two dimension). Typically, arrays are laid out contiguously in memory.
All arrays start start at a fixed lower bound. This rule has no exception. When you create an array in C#, you specify the numbers of elements.Because counting start at 0, the highest index is actually one fewer than the number of elements.

//Create an array with four string (from index 0 to index 3).

//You need to initialize the array with the new keyword in order to use it:
string[] vStringArray1=new string[4];

//Create a 2*4 grid array (with a total of 8 integers).
int[,] vIntArray1=new int[2,4];

Single-Value, or "Simple," Data Binding

You can use single-value data binding to add information anywhere on an ASP.NET page. You can even place information into a control property or as plain text inside as HTML tag. Single-value data binding allows you to take a variable, a property, or an expression and insert it dynamically into a page.

Types of ASP.NET Data Binding

Two types of ASP.NET data binding exist: single-value binding and repeated-value binding.
Single-value data binding is by far the simpler of the two, whereas repeated-value binding provides the foundation for the most advanced ASP.NET data controls.

Data Binding

The basic principle of data binding is this: you tell a control where to find your data and how you want it display, and the control handle the rest of the details. Data binding in ASP.NET is superficially similar to data binding in the world of desktop or client/server application, but in truth, it's fundamentally different.In those environment, data binding involves creating a direct connection between a data source and a control in an application window.if a user change a value in the on-screen control, the data in the linked database is modified automatically. Similarly, if the database changes while the user is working with it (for example, another user commits a change), the display can be refreshed automatically.

Featues of ASP.NET 2.0

ASP.NET 2.0 improves ASP.NET by adding several new features.
Design goals for ASP.NET 2.0:

  • Increase productivity by removing 70% of the code
  • Use the same controls for all types of devices
  • Provides a faster and better web server platform
  • Simplify the administration of web applications
Some of the features in ASP.NET 2.0 are:

  • Master Pages, Themes, and Web Parts
  • Standard controls for navigation
  • Standard controls for security
  • Roles, personalization and internationalization services
  • Improved and simplified data access controls
  • Full support for XML standard like , XHTML, XML, and WSDL
  • Improved compilation and deployment(installation)
  • Improved site management
  • New and improved development tools

Client Side Validation

ASP.NET automatically adds JavaScript code for client side validation.In this case, when the user clicks a CausesValidation button, the same error message will appear without the page needing to be submitted and returned from the server.This increase the representation of your web page.
However, even if the page validates successfully on the client side,ASP.NET still revalidates it when it's received at the server.This is because it's easy for an experienced user to circumvent client side validation. For example, a malicious user might delete the block of JavaScript validation. For example, a malicious user might delete the block of JavaScript validation code and continue working with the page.By performing the validation at both ends,ASP.NET makes sure your application can be responsive as possible while also remaining secure.

Server Side Validation

You can use the validator controls to verify a page automatically when the user submits it or manually in your code.The first approach is the most common.
When using automatic validation,the user receive a normal page and begins to fill in the input controls. When finished, the user clicks a button to submit the page.Every button has a causes Validation property, which can be set to true or false.What happens when the user clicks the button depends on the value of the CausesValidation property.

  • If CausesValidation is false, ASP.NET will ignore the validation controls,the page will be posted back,and your event-handling code will run normally.
  • If CausesValidation is true(the default), ASP.NET will automatically validate the page when the user clicks the button. It does this by performing the validation for each control on the page. If any control fails to validate, ASP.NET will return the page with some error information,depending on your setting.Your click event-handling code may or may not be executed-meaning you'll have to specifically check in the event handler whether the page is valid.

What is methods?

Methods are the most basic building block you can use to organize your code. Essentially,a method is a named grouping of one or more lines of code.Ideally,each method will perform a distinct,logical task.By breaking your code down into methods, you not only simplify your life,but you also make it easier to organize your code into classes and step into the world of object oriented programming.
When you declare a method in C#,the first part of the declaration specifies the data type of the return value,and the second part indicates the method name.If your method doesn't return any information,you should use the void keyword instead of a data type at the beginning of the declaration.
Here are two examples-one method that doesn't return anything and one that does:

// This method doesn't return any information.
void MyMethodNoReturnedData()
{
// Code goes here.
}

// This method returns an integer.
int MyMethodReturnsData()
{
// Return the number 10.
return 10;
}

Method Overloading?

Method overloading, which allows you to create more than one method with the same name,but with a different set of parameters. When you call the method ,the CLR automatically choose the correct version by examining the parameters you supply.
This technique allows you to collect different versions of several methods together. For example, you might allow a database search that returns an array of Product object representing records in the database.Rather than create three methods with different names depending on the criteria,suchasGetProducts(),
GetProductsInCategory(),and GetActiveProducts(),you could create three versions of the GetProducts() methods. Each method would have the same name but a different signature ,meaning it would require different parameters.This example provides two overloaded versions for the GetProductPrice() method:

private decimal GetProductPrice(int ID)
{
// Code here
}
private decimal GetProductPrice(string name)
{
// Code here
}

What is document object?

The document object is the most important information source for most Javascript program , and information about many aspects of the HTML document are represented by the properties found here. It allows you to update a document, which is being displayed and to access the components available in the loaded document.
The document object has several properties. For example the write() method, which you have learn in the earlier section is very useful, and allows the program to generate HTML that will be inserted in the document when it is displayed. Various properties are given below:
  • forms[] :- An array of form objects, one for each
    and
    in the document. The number of forms in the document can be determine using the statement form.length.
  • images[] :- An array of image objects,one for each embedded image. The number of images can be determine using images.length statement.
  • links[] :- An array of link objects, one for each hypertext link in the document. The number of link objects can be determine using links.length statement.

What is Class Library?

  • A class library is the loaded into the application domain that use it.
  • When application use a class library that class library is a loaded into a application. e.g. If a application use a class library A and class library B is use into class library A then both A and B are loaded into the application.

What is namespace?

Namespace in the .NET Runtime are used to organize classes and other types into a single hierarchical structure.Namespace can also be thought of as way to specify really long names for classes and other without having to always type a full name.
Namespace are define using the namespace statement.For multiple levels of organization, namespace can be nested:
namespace Outer
{
namespace Inner
{
class MyClass
{
public static void Function(){}
}
}
}

What is the Global.asax file?

The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET.The Global.asax file is parsed and dynamically compiled by ASP.NET into a .NET Framework class the first time any resource or URL within its application namespace is activated or requested.Whenever the application is requested first time, the Global.asax file is parsed and complied to a class that extends the HttpApplication class.

What is Global.asax?

The Global.asax file(also known as the ASP.NET application file) is an optional file that is located in the application's root directory and is the ASP.NET counterpart of the Global.asax of ASP.This file exposes the application and the session level events in ASP.NET and provides a gateways to all the application and the session level events in ASP.NET.This file can be used to implement the important application and session level events such as Application_Start,Application_End, Session_Start,Session_End,etc.

What is Session?

A session is something that start the moment a user request a web page from your Web site & ends after the user levels.Each visitor to your Web site is given individual session.
Use of Session
  • Session can be used to store a visitor's preferences.
  • Session can also be used to create virtual shopping carts.Whenever a visitor selects an item to buy at your Web site,the item can be added to a shopping cart can be stored in a session.
  • Session can be used to keep of the habits of your visitors.

What is Session State?

A session is define as the period of time that a unique user interacts with a Web application.Session state is a collection of object,tied to a session are stored on a server.
Session state is nothing more than memory in the shape of a dictionary or hash table,e.g. key value pairs,which can be set and read for the duration of a user's session.For example, a user selects stocks to track and the Web application can store these values in the user's ASP session instance:

Session("Stocks")="MSFT;VRSN;GE"

What is Validation Controls?

Validation controls are controls which help us to perform different validation on the data in controls like Textbox,Listbox and radiobutton.The common validation controls we use in a webform are:
  • RequiredFieldValidator Control :- For compulsory required fields
  • RegularExpressionValidator Control :- For Validating expressions
  • CompareValidator Control :- For Comparing values
  • RangeValidator Control :- For checking for a range of values
  • ValidationSummary Control :- For Summarizing Validation Errors

How Does ASP.NET Work?

  • When a browser request an HTML files, the server returns the file
  • When a browser request an ASP.NET files,IIS passes the request to the ASP.NET engine on the server
  • The ASP.NET engine reads the file,line by line,and execute the script in the file
  • The ASP.NET file is returned to the browser as plain HTML.

What is different between ASP and ASP.NET?

  • ASP is the run under the IIS process.
  • ASP.NET is run under the IIS process(ASP.NET_pw.exe and inetinfo.exe also).
  • ASP Language where available for scripting VBScript and JScript.
  • ASP.NET include C# and VB.NET.
  • ASP run on Microsoft Platform only.
  • ASP.NET could be run on none Microsoft Platform.
  • ASP engine execute server side code which is always true an interpreter(JScript,VBScript).
  • ASP.NET pages are compiling to .NET classes.This classes include all of the server side code and static HTML.

What is master page?

A master page is a template for other pages,with shared layout and functionality.The master page define placeholders for content pages.The result page is a combination(merge) of the master page and the content page.

What is an ASP.NET File?

  • An ASP.NET file is just the same as an HTML file
  • An ASP.NET file can contain HTML,XML,and scripts
  • Scripts in an ASP.NET file are executed on the server
  • An ASP.NET file has the file extension ".aspx"

What is ASP.NET?

ASP.NET is a server side scripting technology that enables scripts(embedded in web pages) to be executed by an Internet server.
  • ASP.NET is Microsoft Technology
  • ASP.NET is a program that runs inside IIS
  • IIS(Internet Information Services) is Microsoft's Internet server
  • IIS comes as a free component with Windows servers
  • IIS is also a part of Window 2000 and XP Professional