Complete Dot Net Notes
Complete Dot Net Notes
Constraints: Rules defined on the table which cannot be violated by the users.
A constraint is a property assigned to a column or the set of columns in a table that prevents
certain types of inconsistent data values from being placed in the column(s). Constraints are used
to enforce the data integrity. This ensures the accuracy and reliability of the data in the database
Types:
Domain Integerity Constraints:
Check: Limits the range of values or domain, checks the values which a col can have.
Foreign Key: Referntial integrity b/w 2 tables, one table col values based on other table col
values.
Unique Key: donot allow duplicate values, but allows one null per col.Can have multiple unique
constraints on a table
ACID Properties:
Consistency guarantees that a transaction never leaves your database in a half-finished state.
Isolation keeps transactions separated from each other until they’re finished.
Durability guarantees that the database will keep track of pending changes in such a way that
the server can recover from an abnormal termination
SET ROWCOUNT 1
SELECT 'start'
WHILE @@ROWCOUNT > 0 DELETE E1 FROM EMP2 E1 WHERE (SELECT count(*) FROM EMP2
WHERE EMP2.EMPID=E1.EMPID) >1
SET ROWCOUNT 0
1 HELLO 100
2 HELLO1 200
4 Ravi kiran 300
5 sand 50
6 dilip 120
SQL JOINS
EmployeeID EmployeeName
An Inner Join will take two tables and join them together based on the values in common
columns ( linking field ) from each table.
Example 1 :- To retrieve only the information about those employees who are assinged to a
department.
Select
Employee.EmployeeID,Employee.EmployeeName,Department.DepartmentName
From
Employee
Inner Join
Department
on
Employee.DepartmentID = Department.DepartmentID
Select
Department.DepartmentID,Department.DepartmentName From
Department
Inner Join
Employee
on
Employee.DepartmentID = Department.DepartmentID
*****************************************************************************
******
Outer Joins :-
Left outer join selects all the rows from the left table specified in the LEFT OUTER JOIN clause,
not just the ones in which the joined columns match.
Example 1:- To retrieve the information of all the employees along with their Department Name
if they are assigned to any department.
Right outer join selects all the rows from the right table specified in the RIGHT OUTER JOIN
clause, not just the ones in which the joined columns match.
Example 2:- use Right Outer join to retrieve the information of all the departments along with
the detail of EmployeeName belonging to each Department, if any is available.
Select Department.DepartmentID,Department.DepartmentName,Employee.EmployeeName
From Employee Outer Join Department on Employee.DepartmentID =
Department.DepartmentID
This query will result in Null value for Employee Name where no Employee is assigned to that
department
CROSS JOIN:
A cross join that does not have a WHERE clause produces the Cartesian product of the tables
involved in the join. The size of a Cartesian product result set is the number of rows in the first
-- OR
SELF JOIN:
Self join is just like any other join, except that two instances of the same table will be joined in
the query
Chintu.
Index:
An index can be created by selecting one or more columns in a table that is being searched.
What are the difference between clustered and a non‐clustered index?
A clustered index is a special type of index that reorders the way records in the table are
physically stored. Therefore table can have only one clustered index. The leaf nodes of a
clustered index contain the data pages.
A non clustered index is a special type of index in which the logical order of the index does not
match the physical stored order of the rows on disk. The leaf node of a non clustered index does
not consist of the data pages. Instead, the leaf nodes contain index rows.
DELETE
1 DELETE removes rows one at a time and records an entry in the transaction log for each
deleted row.
2 If you want to retain the identity counter, use DELETE instead. If you want to remove table
definition and its data, use the DROP TABLE statement.
3 DELETE Can be used with or without a WHERE clause
4 DELETE Activates Triggers.
5 DELETE can be rolled back.
6 DELETE is DML Command.
7 DELETE does not reset identity of the table.
UNION:
The UNION command is used to select related information from two tables, much like the
JOIN command. However, when using the UNION command all selected columns need to be of
the same data type. With UNION, only distinct values are selected.
UNION ALL
The UNION ALL command is equal to the UNION command,except that UNION ALL selects all
values.
The difference between Union and Union all is that Union all will not eliminate duplicate rows,
instead it just pulls all rows from all tables fitting your query specifics and combines them into
a table.
VIEW:
A view is a virtual table that consists of columns from one or more tables. Though it is similar to
a table, it is stored in the database. It is a query stored as an object. Hence, a view is an object
that derives its data from one or more tables. These tables are referred to as base or underlying
tables. Once you have defined a view, you can reference it like any other table in a database.
A view serves as a security mechanism. This ensures that users are able to retrieve and modify
only the data seen by them. Users cannot see or access the remaining data in the underlying
tables. A view also serves as a mechanism to simplify query execution. Complex queries can be
stored in the form as a view, and data from the view can be extracted using simple queries.
• A view behaves like a virtual table. Since you can code a view name anywhere you can
code a table name. a view is sometimes called a viewed table.
• Views can be used to restrict the data that a user is allowed to access or to present data
in a form that is easy for the user to understand. In some database users may be allowed
to access data only through views.
Stored Procedure
A stored procedure is a set of one or more SQL statements that are stored together in database.
To create a stored procedure use CREATE PROCEDURE statement. To use the stored procedure
you send a request for it to be executed. When server receives the request, it executes the
stored procedure.
Stored procedures can also improve performance. Many tasks are implemented as a series of SQL
statements. Conditional logic applied to the results of the first SQL statements determines which
subsequent SQL statements are executed. If these SQL statements and conditional logic are
written into a stored procedure, they become part of a single execution plan on the server. The
results do not have to be returned to the client to have the conditional logic applied; all of the
work is done on the server.
• A stored procedure is one or more SQL statements that have been compiled and stored
with database. A stored procedure can be started by application code on the client.
• Stored procedure can improve database performance because the SQL statements in each
procedure are only compiled and optimized the first time they are executed. In sontrast
SQL statements that are sent from a client to the server have to be compiled and
optimized everytime ther are executed.
• In addition to SELECT statement, a stored procedure can contain othe SQL statements
such as INSERT,UPDATE,DELETE. It also contain control-of-flow language.
• A trigger is a special type of procedure that executes when rows are inserted, updated or
deleted from table.
• A user defined function(UDF) is a special type of procedure that can return a value or a
table.
•
Example:
END
CURSORS
For example, you can use a single UPDATE statement to update many rows of data. There are
times when you want to loop through a series of rows a perform processing for each row. In this
case you can use a cursor
Example of a cursor
TRIGGERS
A trigger is a special kind of stored procedure that is invoked whenever an attempt is made to
modify
the data in the table it protects. Modifications to the table are made ussing INSERT,UPDATE,OR
DELETE
statements.Triggers are used to enforce data integrity and business rules such as automatically
updating summary data. It allows to perform cascading delete or update operations. If
constraints exist on the trigger table,they are checked prior to the trigger execution. If
constraints
are violated statement will not be executed and trigger will not run.Triggers are associated with
/* INSERT TRIGEER */
/* UPDATE TRIGEER */
/* DELETE TRIGEER */
ExecuteScalar - Returns only one value after execution of the query. It returns the first field in
the first row. This is very light-weight and is perfect when all your query asks for is one item. This
would be excellent for receiving a count of records (Select Count(*)) in an sql statement, or for
any query where only one specific field in one column is required.
Example:
SqlCommand cmd = new SqlCommand("Insert Into t_SomeTable Values('1','2')",con);
//note that con is the connection object
con.Open();
cmd.ExecuteNonQuery(); //The SQL Insert Statement gets executed
ExecuteReader - This method returns a DataReader which is filled with the data that is retrieved
using the command object. This is known as a forward-only retrieval of records. It uses our SQL
statement to read through the table from the first to the last record.
A DataReader object represents a forward only, read only access to data from a source. It
implements IDataReader & IDataRecord interfaces. For example, The SQLDataReader class can
read rows from tables in a SQL Server data source. It is returned by the ExecuteReader method
of the SQLCommand class, typically as a result of a SQL Select statement. The DataReader class'
HasRows property can be called to determine whether the DataReader retrieved any rows from
the source. This can be used before using the Read method to check whether any data has been
retrieved.
Example
Dim objCmd as New SqlCommand("Select * from t_Employees", objCon)
objCon.Open()
Dim objReader as SqlDataReader
objReader = objCom.ExecuteReader(CommandBehavior.CloseConnection)
If objReader.HasRows = True then
Do While objReader.Read()
ListBox1.Items.Add(objReader.GetString(0) & vbTab & objReader.GetInt16(1))
Loop
End If
objReader.Close()
(NOTE: XmlReader object is used for Forward only Read only access of XML).
Example
Dim objCon as SqlConnection = New
SqlConnection("server=(local);database=NameOfYourDb;user id=sa; password=;)
Dim da as New SqlDataAdapter
Dim ds as DataSet = New DataSet
da.SelectCommand.Connection = objCon 'The Data Adapter manages on its own, opening &
closing of connection object
da.SelectCommand.CommandText = "Select * from t_SomeTable"
da.Fill(ds,"YourTableName")
Gridview1.DataSource = ds
Gridview1.DataMember = "YourTableName"
Gridview1.Databind()
1)@ Assembly
Links an assembly to the current page or user control
declaratively.
2)@ Control
Defines control-specific attributes used by the ASP.NET
page parser and compiler and can be included only in .ascx
files (user controls).
3)@ Implements
Indicates that a page or user control implements a
specified .NET Framework interface declaratively.
4)@ Import
Imports a namespace into a page or user control explicitly.
5)@ Master
Identifies a page as a master page and defines attributes
used by the ASP.NET page parser and compiler and can be
included only in .master files.
6)@ MasterType
Defines the class or virtual path used to type the Master
property of a page.
7)@ OutputCache
Controls the output caching policies of a page or user
control declaratively.
8)@ Page
Defines page-specific attributes used by the ASP.NET page
parser and compiler and can be included only in .aspx files.
9)@ PreviousPageType
Creates a strongly typed reference to the source page from
the target of a cross-page posting.
10)@ Reference
Links a page, user control, or COM control to the current
page or user control declaratively.
11)@ Register
Associates aliases with namespaces and classes, which
allow user controls and custom server controls to be
FORMS AUTHENTICATION
Forms authentication uses an authentication ticket that is created when a user logs on to a site,
and then it tracks the user throughout the site. The forms authentication ticket is usually
contained inside a cookie. However, ASP.NET version 2.0 supports cookieless forms
authentication, which results in the ticket being passed in a query string.
ASP.NET forms authentication occurs after IIS authentication is completed. You can configure
forms authentication with the forms element.
Login.aspx.cs:
Web.Config:
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="login.aspx"
protection="All" path="/" timeout="30" />
</authentication>
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>
string strRedirect;
strRedirect = Request["ReturnUrl"];
if (strRedirect == null)
strRedirect = "default.aspx";
Response.Redirect(strRedirect, true);
}
else
Response.Redirect("login.aspx", true);
}
Important Notes:
• You may want to store passwords securely in a database. You can use the
FormsAuthentication class utility function named
HashPasswordForStoringInConfigFile to encrypt the passwords before you store them
in the database or configuration file.
• Forms-based authentication requires that your client accept or enable cookies on their
browser.
Convert the password into a secured format
string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPwd.Text, "SHA1");
Session state is a server side tool for managing state. Every time your web app goes to the
server to get the next request, the server has to know how much of the last web page needs to
be "remembered" when the new information is sent to the web page. The process of knowing the
values of controls and variables is known as state management.
When a page postback occurs, ASP.Net has many techniques to remember state information.
Some of these state management information methods are on the client side and others are on
the server side. Client side methods for maintaining state include query strings, cookies, hidden
fields and view state.
Most client side state management modes can be read by users and other programs, meaning
that user ids and passwords can be stolen. But session state sits on the server and the ability for
other users to capture this information is reduced and in some cases eliminated.
The importance of this method is the server, especially in a web farm, can know if a particular
user is a new user or has already visited this web page. Imagine in a web farm, where you have
multiple servers serving the same web page. How do the servers recognize unique visitors? It is
through the session id. Even if server one gets the initial request, server two and server three
can recognize user A as already having a session in process.
Now the server can store session specific information about the current user. Is there highly
critical sensitive information about the user that needs to be remembered? Like credit card
information or name, address and phone number? This information can be kept out of the prying
eyes of internet identity thieves with session state.
txtName.Text = Session["Name"].ToString();
You can store simple objects like strings into the session state and you can also store more
complex objects like arrays and structs and any object derived from System.Object.
Abandon
Cancels the current session
Clear
Clears all values from session state
CopyTo
Copies the collection of session state values to a one dimensional array, starting at the
specified index in the array.
Equals
Determines if the specified object is equal to the current session state object
GetEnumerator
Gets an enumerator of all session state values in the current session
GetType
Gets the System.Type of the current instance
Remove
Deletes an item from the session-state collection
RemoveAll
Clears all session state values
RemoveAt
Deletes an item at a specified index from the session state collection.
ToString
Returns a System.String that represents the current System.Object
As you can see by looking at the supported methods, you can add, remove, remove all, convert
to a string and detrmine type.
1. In Process
State Service runs in a different process than ASP.Net, so you don't have to worry about losing
information when ASP.net goes down. State Service also enables you to share your state across
multiple servers (web farm) and multiple processors on one server (web garden).
A disadvantage to using session state is because it is stored on the server you must go to the
For the greatest safety and security of your session state use MSSQL server to store session
state. Then even if the SQL server dies, you still maintain the info needed for session state. A
great methodology to use if you are running an eCommerce shopping cart. Users dislike it when
their session dies and they don't know if they have pruchased something or not.
Since it is stored outside of the web server and the client, then you don't lose information if the
web garden or web farm go down either. To use session state on the SQL server alter your
web.config file:
So to store required information outside of the client and to persist the information pass each
page load use Session State. It is part of the HttpSessionState class and comes from the Page
class. It is easy to use, but does require resources on the server, which could slow response time.
You can store sessionState in-process, state server or in SQL server. You don't need to store
everything in sessionState, but you add a level of trust to the items stored in sessionState.
In ASP.Net there are four ways to manage client side state. What does that mean client side state
management? When your user clicks on an URL or button or server side control, the information
goes from your page to the server and then back again to the users web browser. How do you
remember the information that is currently on the page. These are the techniques to save the
information on the client side and not the server side.
Unlike a client server application, there is no automatic storage of information from the previous
browser page. Therefore the ASP.Net developer has to take steps to save important information
from the postback to the server.
1. Query String
2. Cookies
3. Hidden Fields
4. View State
This article will discuss the advantages and disadvantages of each method of state management.
This is a continuation of an article on client side state management. This section will discuss
hidden fields and ASP.Net viewstate.
Hidden Fields
The next client side state management technique for ASP.Net is hidden fields. Hidden fields
have been around for a long time. This is where you place a text field control on your html page.
Then you set the control to hidden. That means that your user cannot see the control or its value
Hidden fields are not displayed on the web browser, but if you view source, you can see both the
hidden field and it's value. Not very secure. They do allow you to post information to other
pages, or back to the same page.
ViewState
Next on our list of client side state management methods is Viewstate. This is an ASP.Net tool
that allows you to maintain the state of your controls like textbox and listbox across page
postbacks.
Viewstate has advantages the other 3 methods don't have. One of the most important is the
ability of viewstate to support structured data. This means that control values are maintainable
across page postbacks.
1. The more controls you have on the form the larger the size of viewstate and the larger the
size of the HTML you send back and forth to the server.
Since viewstate is saved as HTML, ASP.Net gives you the ability to disable viewstate for individual
For an individual control, just change the EnableViewState property to false to disable the
control's viewstate. When a page doesn't postback to itself, meaning it is always sent to a new
page, you can disable the page viewstate by addding a page directive.
Query String
The query string is a holdover from the ASP days of web programming. You will see this alot
when you are surfing around the internet. Basically, it is passing information to the next page
with the URL. In it's simplest form it is an URL, with a question mark ?, followed by a key value
pair.
So let's say you wanted to pass the user's name to the next page requested. Your redirected URL
is http:/www.youcanlearnseries.com?name=Joe+Smith. When the user goes to the next
page, the developer only needs to capture the query string in the page postback and you have
successfully "saved" information from the previous page.
myURL.com?name=joe+smith&state=Illinois
To pass a value to the querystring use:
Request.QueryString["state"] = sState.ToString();
One of the advantages to using querystring is it requires no postback operation from the server.
The limitations and disadvantages include:
1. There is a limit to the number of characters browsers will allow the length of the
querystring to be.
2. There is virtually no security with querystring. Any information you send in a querystring
can be read by anybody else.
4. You are limited to using only strings. There is no support for storing structured data, such
as ArrayLists, controls, structures or classes.
There is still a lot of uses of querystring, because it is simple to read and send the key value pair
between pages, you just have to careful what you send and you have to know the limitations of
the querystring.
Cookies
Next is the ASP classic cookies. You are aware of cookies. When you go to a website and the
website leaves a txt file on your computer that contains information for the website to use the
The Advantages of cookies include the fact that the information can be persisted on the user's
computer. You can set the cookies expire property to automatically expire the cookie after a
certain time.
//First check to see if the cookie is available anymore. Many power users delete
//their cookies on a regular basis to improve performance.
if (Request.Cookies["UserName"] == null)
{
//The cookie is not available go on without it.
}
else
{
//Cookie is still there let's read it.
string sUserName = Request.Cookies["UserName"].Value;
}
Cookies have their place in the internet world. I go to a site on a regular basis. They place a
cookie on my computer and know who I am when I arrive. It saves me the time of having to login
when I want to comment in their forum.
Trace and Debug - There are two main classes that deal with tracing - Debug and Trace. They
both work in a similar way - the difference is that tracing from the Debug class only works in
Tracing is actually the process of collecting information about the program's execution. Debugging
is the process of finding & fixing errors in our program. Tracing is the ability of an application to
generate information about its own execution. The idea is that subsequent analysis of this
information may help us understand why a part of the application is not behaving as it should and
allow identification of the source of the error.
We shall look at two different ways of implementing tracing in .NET via the
System.Web.TraceContext class via the System.Diagnostics.Trace and
System.Diagnostics.Debug classes. Tracing can be thought of as a better alternative to the
response.writes we used to put in our classic ASP3.0 code to help debug pages.
If we set the Tracing attribute of the Page Directive to True, then Tracing is enabled. The output is
appended in the web form output. Messeges can be displayed in the Trace output using
Trace.Warn & Trace.Write.
NOTE The only difference between Trace.Warn & Trace.Write is that the former has output in red
color. If the trace is false, there is another way to enable tracing. This is done through the
application level. We can use the web.config file and set the trace attribute to true. Here we can
set <trace enabled=false .../>
Note that the Page Directive Trace attribute has precedence over th application level trace
attribute of web.config. While using application level tracing, we can view the trace output in
the trace.axd file of the project.
Both "Server" and "Response" are objects of ASP.NET. Server.Transfer and Response.Redirect
both are used to transfer a user from one page to another. But there is an underlying difference.
The Response.Redirect statement sends a command back to the browser to request the next
page from the server. This extra round-trip is often inefficient and unnecessary, but this
established standard works very well. By the time Page2 is requested, Page1 has been flushed
from the server’s memory and no information can be retrieved about it unless the developer
explicitly saved the information using some technique like session, cookie, application, cache etc.
The more efficient Server.Transfer method simply renders the next page to the browser
without an extra round trip. Variables can stay in scope and Page2 can read properties directly
from Page1 because it’s still in memory. This technique would be ideal if it wasn’t for the fact that
the browser is never notified that the page has changed. Therefore, the address bar in the
browser will still show “Page1.aspx” even though the Server.Transfer statement actually caused
Page2.aspx to be rendered instead. This may occasionally be a good thing from a security
perspective, it often causes problems related to the browser being out of touch with the server.
Say, the user reloads the page, the browser will request Page1.aspx instead of the true page
Both Server.Transfer and Server.Execute were introduced in Classic ASP 3.0 (and still work in
ASP.NET).
When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to
this new page. Execution of code happens on the new page. Once code execution gets over, the
control returns to the initial page, just after where it was called. However, in the case of
Server.Transfer, it works very much the same, the difference being the execution stops at the
new page itself (means the control is'nt returned to the calling page).
In both the cases, the URL in the browser remains the first page url (does'nt refresh to the new
page URL) as the browser is'nt requested to do so.
Authentication is the mechanism whereby systems may securely identify their users.
Authentication systems depend on some unique bit of information known only to the individual
being authenticated and the authentication system.
Authorization is the mechanism by which a system determines what level of access a particular
authenticated user should have to secured resources controlled by the system.
When a user logs on to an application/system, the user is first Authenticated, and then
Authorized.
The Authentication Provider performs the task of verifying the credentials of the user ans decides
whether a user is authenticated or not. The authentication may be set using the web.config file.
WEBSERIVCES SECURITY
Default.aspx.cs:
dgData.DataSource = dsData;
dgData.DataBind();
}
AuthHeader.cs :
}
else
{
data = null;
}
return data;
}
Explain the access specifiers Public, Private, Protected, Friend, Internal, Default
The main purpose of using access specifiers is to provide security to the applications. The
availability (scope) of the member objects of a class may be controlled using access specifiers.
1. PUBLIC
As the name specifies, it can be accessed from anywhere. If a member of a class is defined as
public then it can be accessed anywhere in the class as well as outside the class. This means that
objects can access and modify public fields, properties, methods.
2. PRIVATE
As the name suggests, it can't be accessed outside the class. Its the private property of the class
and can be accessed only by the members of the class.
3. FRIEND/INTERNAL
Friend & Internal mean the same. Friend is used in VB.NET. Internal is used in C#. Friends can be
accessed by all classes within an assembly but not from outside the assembly.
4. PROTECTED
Protected variables can be used within the class as well as the classes that inherites this class.
5. PROTECTED FRIEND/PROTECTED INTERNAL
The Protected Friend can be accessed by Members of the Assembly or the inheriting class, and
ofcourse, within the class itself.
6. DEFAULT
A Default property is a single property of a class that can be set as the default. This allows
developers that use your class to work more easily with your default property because they do
not need to make a direct reference to the property. Default properties cannot be initialized as
Shared/Static or Private and all must be accepted at least on argument or parameter. Default
properties do not promote good code readability, so use this option sparingly
Whats the difference betweeen Structure, Class and Enumeration ?
struct MyStruct
{
public int y,z;
}
and we create a structure type
MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class
keyword.
class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
}
A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit
from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting
of a set of named constants called the enumerator list. Every enumeration has an underlying
type. The default type is "int". Note: char cant be the underlying data type for enum. First
value in enum has value 0, each consequent item is increased by 1.
enum colors
{red, green, blue, yellow};
int x = (int)colors.yellow;
Above, an abstract class named Vehicle has been defined. We may use the fields, properties and
member functions defined within this abstract class to create child classes like Car, Truck, Bike
etc. that inherit the features defined within the abstract class. To prevent directly creating an
instance of the class Vehicle, we make use of the abstract keyword. To use the definitions defined
in the abstract class, the child class inherits from the abstract class, and then instances of the
Child class may be easily created.
Further, we may define abstract methods within an abstract class (analogous to C++ pure virtual
functions) when we wish to define a method that does not have any default implementation. Its
then in the hands of the descendant class to provide the details of the method. There may be any
number of abstract methods in an abstract class. We define an abstract method using the
abstract keyword. If we do not use the abstract keyword, and use the virtual keyword instead,
we may provide an implementation of the method that can be used by the child class, but this is
not an abstract method.
Remember, abstract class can have an abstract method, that does not have any implementation,
for which we use the abstract keyword, OR the abstract class may have a virtual method, that
can have an implementation, and can be overriden in the child class as well, using the override
keyword. Read example below
1) A class may inherit only one abstract class, but may implement multiple number of Interfaces.
Say a class named Car needs to inherit some basic features of a vehicle; it may inherit from an
Aabstract class named Vehicle. A car may be of any kind, it may be a vintage car, a sedan, a
coupe, or a racing car. For these kind of requirements, say a car needs to have only two seats
(means it is a coupe), then the class Car needs to implement a member field from an interface,
that we make, say ICoupe.
2) Members of an abstract class may have any access modifier, but members of an interface are
public by default, and cant have any other access modifier.
3) Abstract class methods may OR may not have an implementation, while methods in an
Interface only have a definition, no implementation.
Both Overriding and Shadowing are ways to alter the behaviour of members of a base class.
Shadowing is a VB.NET concept. In C#, this concept is called Hiding, though there is a difference
between the two.
When we do shadowing, we provide a new implementation to the base class member without
overriding it. We may shadow a base class member in a derived class
, by using the keyword shadows. The access level, return type, and the signature (means the
datatypes of the arguments passed & the order of the types) of the derived class members which
are shadowed, may differ from the base class.
In C#, we may achieve shadowing using the keyword new. However, when Hiding in C#, the
access level, the signature, return type of the derived class must be same as the base class.
In any object Oriented language, an object is the backbone of everything that we see. A class is a
blueprint that describes how an instance of it (object) will behave. To create a class, we define it
in a "Code File", with an extension *.cs or *.vb. We make use of the keyword class.
Example
Lets create a class named Laptop
Once the class object is created, the object may be used to invoke the member functions defined
within the class. We may allocate any number of objects using the new keyword. The new
keyword returns a reference to an object on the heap. This reference is not to the actual object
itself. The variable being refered is stored on a stack for usage in the application. When we
allocate an object to a heap, its managed by the .NET runtime. The garbage collector takes care
of the object by removing it from the heap, when it is no longer reachable by any part of the
code.
What is the difference between value type and reference type? Can a value type
contain NULL values?
In simple words, all value based types are allocated on the stack, while all reference based types
are allocated on the heap. What does this mean? A value type contains the actual value. A
reference type contains a reference to the value. When a value type is assigned to another value
type, it is copied. When a reference type is assigned to another reference type, a reference is
assigned to the value.
By saying stack, we mean things are kept one on top of the other. We keep track of each value at
the top. By saying heap, we mean things are kept in a mashed order. We keep track of each value
by its address, that is referenced by a pointer to it.
All value types are implicitly derived from System.ValueType. This class actually overrides the
implementation in System.Object, the base class for all objects which is a reference type itself.
Data types like integers, floating point numbers, character data, Boolean values, Enumerations
and Structures are examples of Value Types. Classes, Strings, Arrays are examples of Reference
Types.
A value type may not contain NULL values. Reference types may contain NULL values.
It is not possible to derive new types from Value Types. This is possible in Reference types.
However, Value Types like Structures can implement interfaces.
In .NET, an assembly may become a DLL or an EXE. Yet, there is a major underlying difference
between the two.
An EXE is an executable file that may run on its own. It’s independent. Where as a DLL is a
Dynamic Link Library, that binds to an exe, or another DLL at runtime.
A DLL has an exposed interface, through which members of the assembly may be accessed by
A DLL runs in tandem with the application space in memory, as the application references it.
Whereas an EXE is independent, and runs as an independent process.
The most common operation with a string is concatenation. This activity has to be performed very
efficiently. When we use the "String" object to concatenate two strings, the first string is
combined to the other string by creating a new copy in the memory as a string object, and then
the old string is deleted. This process is a little long. Hence we say "Strings are immutable".
When we make use of the "StringBuilder" object, the Append method is used. This means, an
insertion is done on the existing string. Operation on StringBuilder object is faster than String
operations, as the copy is done to the same location. Usage of StringBuilder is more efficient in
case large amounts of string manipulations have to be performed.
Both Remoting and Web Services are ways of communication between applications.
Remoting - In remoting, the applications involved in the communication process may be located
on the same computer, different computers in a same or different network. In remoting, both
applications know about each other. A proxy of an application object is created on the other
application.
An assembly is the basic building block in .NET. It is the compiled format of a class, that contains
Metadata, Manisfest & Intermediate Language code.
An assembly may be either Public or Private. A public assembly means the same as Shared
Assembly.
Private Assembly - This type of assembly is used by a single application. It is stored in the
application's directory or the applications sub-directory. There is no version constraint in a private
assembly.
Shared Assembly or Public Assembly - A shared assembly has version constraint. It is stored
in the Global Assembly Cache (GAC). GAC is a repository of shared assemblies maintained by
the .NET runtime. It is located at C:\Windows\Assembly OR C:\Winnt\Assembly. The
shared assemblies may be used by many applications. To make an assembly a shared assembly,
it has to be strongly named. In order to share an assembly with many applications, it must
have a strong name.
A Strong Name assembly is an assembly that has its own identity, through its version and
uniqueness.
In order to convert a private assembly to a shared assembly, i.e. to create a strongly named
assembly, follow the steps below...
1) Create a strong key using the sn.exe tool. This is used to created a cryptographic key pair.
The key pair that is generated by the Strong Name tool can be kept in a file or we can store it our
your local machine's Crytographic Service Provider (CSP). For this, goto the .NET command
interpreter, and type the following...
sn -k C:\samplekey.snk
This will create a strong key and save it to the location C:\samplekey.snk 2) If the key is stored
in a file, just like we have done above, we use the attribute AssemblyKeyFileAttribute. This
belongs to the namespace System.Reflection.AssemblyKeyFileAttribute. If the key was in
the CSP, we would make use of System.Reflection.AssemblyKeyNameAttribute.
Go to the assemblyinfo.vb file of your project. Open this file. Make the following changes in this
file...
<assembly: assemblykeyfileattribute("C:\samplekey.snk")>
Imports System.Reflection
<assembly: assemblykeyfileattribute("C:\samplekey.snk")>
Namespace StrongName
Public class Sample
End Class
End Namespace
The Clone() method returns a new array (a shallow copy) object containing all the elements in
the original array. The CopyTo() method copies the elements into another existing array. Both
perform a shallow copy.
It is possible to split the definition of a class or a struct, or an interface over two or more source
files. Each source file contains a section of the class definition, and all parts are combined when
the application is compiled. There are several situations when splitting a class definition is
desirable:
When working on large projects, spreading a class over separate files allows multiple
programmers to work on it simultaneously.
When working with automatically generated source, code can be added to the class without
having to recreate the source file. Visual Studio uses this approach when creating Windows
Forms, Web Service wrapper code, and so on. You can create code that uses these classes
without having to edit the file created by Visual Studio.
To split a class definition, use the partial keyword modifier, as shown below
With C# 2.0 it is possible to split definition of classes, interfaces and structures over more
than one files.
This feature allows you to do a couple of fancy things like:
1- More than one developer can simultaneously write the code for the class.
2- You can easily write your code (for extended functionality) for a VS.NET generated class. This
will allow you to write the code of your own need without messing with the system generated
code.
There are a few things that you should be careful about when writing code for partial classes:
1- All the partial definitions must preceede with the key word "Partial".
2- All the partial types meant to be the part of same type must be defined within a same
assembly and module.
3- Method signatures (retrn type, name of the method, and parameters) must be unique for the
agregated typed (which was defined partially). i.e. you can write default constructor in two
separate definitions for a particular partial classe.
There are several rules to follow when working with partial class definitions:
All partial-type definitions meant to be parts of the same type must be defined in the same
assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple
modules.
The class name and generic-type parameters must match on all partial-type definitions. Generic
types can be partial. Each partial declaration must use the same parameter names in the same
order.
The following keywords on a partial-type definition are optional, but if present on one partial-type
definition, cannot conflict with the keywords specified on another partial definition for the same
type
• public
• private
• protected
• internal
• abstract
• sealed
• base class
Partial Method:
A partial class or struct may contain a partial method. One part of the class contains the
signature of the method. An optional implementation may be defined in the same part
or another part. If the implementation is not supplied, then the method and all calls to the
method are removed at compile time.
even if the implementation is not supplied. No compile-time or run-time errors will result if the
method is called but not implemented.
**A partial method declaration consists of two parts: the definition, and the implementation.
These may be in separate parts of a partial class, or in the same part. If there is no
implementation declaration, then the compiler optimizes away both the defining declaration and
all calls to the method.
// Definition in file1.cs
partial void onNameChanged();
// Implementation in file2.cs
partial void onNameChanged()
{
// method body
}
Class Inheritance
This lesson teaches about C# Inheritance. Our objectives are as follows:
Implement Base Classes.
Implement Derived Classes.
Initialize Base Classes from Derived Classes.
Learn How to Call Base Class Members.
Learn How to Hide Base Class Members.
Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse
existing code. Through effective employment of reuse, you can save time in your programming.
Listing 8-1. Inheritance: BaseClass.cs
using System;
child.print();
}
Listing 8-1 shows two classes. The top class is named ParentClass and the main class is called
ChildClass. What we want to do is create a child class, using existing code from ParentClass.
First we must declare our intention to use ParentClass as the base class of ChildClass. This is
accomplished through the ChildClass declaration public class ChildClass : ParentClass. The base
class is specified by adding a colon, ":", after the derived class identifier and then specifying the
base class name.
Note: C# supports single class inheritance only. Therefore, you can specify only one base class to
inherit from. However, it does allow multiple interface inheritance, a subject covered in a later
lesson.
ChildClass has exactly the same capabilities as ParentClass. Because of this, you can also say
ChildClass "is" a ParentClass. This is shown in the Main() method of ChildClass when the print()
method is called. ChildClass does not have its own print() method, so it uses the ParentClass
print() method. You can see the results in the 3rd line of output.
Base classes are automatically instantiated before derived classes. Notice the output from Listing
8-1. The ParentClass constructor executed before the ChildClass constructor.
Listing 8-2. Derived Class Communicating with Base Class: BaseTalk.cs
using System;
Polymorphism
This lesson teaches about Polymorphism in C#. Our objectives are as follows:
Learn What Polymorphism Is.
Implement a Virtual Method.
Override a Virtual Method.
Use Polymorphism in a Program.
Another primary concept of object-oriented programming is Polymorphism. It allows you to
invoke derived class methods through a base class reference during run-time. This is handy when
you need to assign a group of objects to an array and then invoke each of their methods. They
won't necessarily have to be the same object type. However, if they're related by inheritance, you
can add them to the array as the inherited type. Then if they all share the same method name,
that method of each object can be invoked. This lesson will show you how to accomplish this.
Listing 9-1. A Base Class with a Virtual Method: DrawingObject.cs
using System;
return 0;
}
}
Listing 9-3 shows a program that uses the classes defined in Listing 9-1 and Listing 9-2. This
program implements polymorphism. In the Main() method of the DrawDemo class, there is an
array being created. The type of object in this array is the DrawingObject class. The array is
named dObj and is being initialized to hold four objects of type DrawingObject.
Next the dObj array is initialized. Because of their inheritance relationship with the
DrawingObject class, the Line, Circle, and Square classes can be assigned to the dObj array.
Without this capability, you would have to create an array for each type. Inheritance allows
derived objects to act like their base class, which saves work.
After the array is initialized, there is a foreach loop that looks at each element of the array. Within
the foreach loop the Draw() method is invoked on each element of the dObj array. Because of
polymorphism, the run-time type of each object is invoked. The type of the reference object from
the dObj array is a DrawingObject. However, that doesn't matter because the derived classes
override the virtual Draw() method of the DrawingObject class. This makes the overriden Draw()
methods of the derived classes execute when the Draw() method is called using the
DrawingObject base class reference from the dObj array. Here's what the output looks like:
Output:
I'm a Line.
I'm a Circle.
I'm a Square.
I'm just a generic drawing object.
The override Draw() method of each derived class executes as shown in the DrawDemo program.
The last line is from the virtual Draw() method of the DrawingObject class. This is because the
actual run-time type of the fourth array element was a DrawingObject object.
Delegates .Net:
A delegate is a type that defines a method signature. When you instantiate a delegate, you can
associate its instance with any method with a compatible signature. You can invoke (or call) the
method through the delegate instance.
Delegates are used to pass methods as arguments to other methods. Event handlers are nothing
more than methods that are invoked through delegates. You create a custom method and a class
such as a windows control can call your method when a certain event occurs. The following
example shows a delegate declaration:Let us have a look at the following sample code.
class Figure
{
public Figure(float a, float b, float c)
{
m_xPos = a;
Events:
Delegate usefulness does not just lie in the fact that it can hold the references to functions but
in the fact that it can define and use function names at runtime and not at compile time. A large
goal of design delegates is their applicability in events model of .Net. Events are the actions of
the system on user manipulations (e.g. mouse clicks, key press, timer etc.) or any event
triggered by the program. To understand the usage of delegates for event model, the previous
examples are used here. We should add to our Figure class next things:
public delegate void FigureHandler(string msg);
public static event FigureHandler Inverted;
public void InvertZ()
{
m_zPos = - m_zPos;
Inverted("inverted by z-axis");
sealed class:
Sealed classes are used to restrict the inheritance feature of object oriented programming. Once
a class is defined as sealed class, this class cannot be inherited.
In C#, the sealed modifier is used to define a class as sealed. In Visual Basic .NET,
NotInheritable keyword serves the purpose of sealed. If a class is derived from a sealed class,
compiler throws an error.
If you have ever noticed, structs are sealed. You cannot derive a class from a struct.
The following class definition defines a sealed class in C#:
// Sealed class
sealed class SealedClass
{
....
}
In the following code, I create a sealed class SealedClass and use it from Class1. If you run this
code, it will work fine. But if you try to derive a class from sealed class, you will get an error.
using System;
class Class1
{
static void Main(string[] args)
{
SealedClass sealedCls = new SealedClass();
int total = sealedCls.Add(4, 5);
Console.WriteLine("Total = " + total.ToString());
}
}
// Sealed class
sealed class SealedClass
Description :
1. Both are used for comparison and boll returns the boolean value (true/false)
but in case a and b both are different datatype then also a.Equals(b) can be used to compare
but incase of == we cant event compaile the code if a and b are different data type
Example :
int a=0;
string b="o";
if(a.Equals(b))
{
//do some thing
}
//above code will compile successfully and internally the int b will convert to object type and
compare
if(a==b)
{
//do some thing
}
//above code will give you the compilation error
Ans: If you're totally sure that the expression is the same type that it's being cast to, use
DirectCast. If there is any doubt, use CType.
Use DirectCast if you're absolutely positively sure that an object is the specified type and the run-
time type of the expression are the same. If you're not sure but expect that the conversion will
work, use CType. The run-time performance of DirectCast is better than that of CType. However,
DirectCast throws an InvalidCastException error if the argument types do not match, so you must
be sure.
.
IS operator: used to check whether the run-time type of an object is compatible with a given
type.
How will you copy the structure of a table without data ? or write a query to replicate
the table without data in another table ?
Object Pooling:
Object Pooling is something that tries to keep a pool of objects in memory to be re-used later and
hence it will reduce the load of object creation to a great extent. This article will try to explain
this in detail. The example is for an Employee object, but you can make it general by using
Object base class.
Object Pool is nothing but a container of objects that are ready for use. Whenever there is a
request for a new object, the pool manager will take the request and it will be served by
allocating an object from the pool.
Connection Pooling
Basics
Connection pooling behavior is controlled by the connection string parameters. The following are
four parameters that control most of the connection pooling behavior:
• Connect Timeout - controls the wait period in seconds when a new connection is
requested, if this timeout expires, an exception will be thrown. Default is 15 seconds.
• Max Pool Size - specifies the maximum size of your connection pool. Default is 100. Most
Web sites do not use more than 40 connections under the heaviest load but it depends on
how long your database operations take to complete.
• Min Pool Size - initial number of connections that will be added to the pool upon its
creation. Default is zero; however, you may chose to set this to a small number such as 5
if your application needs consistent response times even after it was idle for hours. In this
case the first user requests won't have to wait for those database connections to establish.
• Pooling - controls if your connection pooling on or off. Default as you may've guessed is
true. Read on to see when you may use Pooling=false setting.
In This Section
Common Language Runtime Overview
Introduces managed code, managed data, and metadata, and describes key features of
Related Sections
Hosting the Common Language Runtime
Describes runtime hosts, which are sections of code that load the runtime into a process,
create the application domains within the process, and load and run user code within
those application domains.
Common Type System
Describes and defines how types are declared, used, and managed in the runtime in
support of cross-language integration.
Within each stage of the life cycle of a page, the page raises events that you can handle to run
your own code. For control events, you bind the event handler to the event, either declaratively
using attributes such as onclick, or in code.
Pages also support automatic event wire-up, meaning that ASP.NET looks for methods with
particular names and automatically runs those methods when certain events are raised. If the
AutoEventWireup attribute of the @ Page directive is set to true (or if it is not defined, since by
default it is true), page events are automatically bound to methods that use the naming
convention of Page_event, such as Page_Load and Page_Init. For more information on
automatic event wire-up, see ASP.NET Web Server Control Event Model.
The following table lists the page life-cycle events that you will use most frequently. There are
more events than those listed; however, they are not used for most page processing scenarios.
Instead, they are primarily used by server controls on the ASP.NET Web page to initialize and
render themselves. If you want to write your own ASP.NET server controls, you need to
understand more about these stages. For information about creating custom controls, see
Developing Custom ASP.NET Server Controls.
Note:
If the request is a postback, the values of the controls have not yet
The params keyword allows methods to have a variable length parameter list.
For example, the following class defines a method called "MultiPrint", which can have any number
of string's passed to it.
using System;
public class MyApplication
{
MultiPrint("Fourth");
MultiPrint("Fifth", "Sixth");
}
}
First
Second
Third
Fourth
DOTNET MATERIAL Page 47
Fifth
Sixth
There can only be one params keyword per method declaration, and it can only be on the final
parameter in the list
CLR:
The .NET Framework provides a Runtime environment called the Common Language Runtime or
(CLR) that handles the execution of the code and provides useful services for the implementation
of the application. CLR takes care of code management upon program execution and provides
various services such as memory management, thread management, security management and
other system services. The managed code targets CLR benefits by using useful features such as
cross-language integration, cross-language exception handling, versioning, enhanced security,
deployment support, and debugging.
Common Type System (CTS) describes how types are declared, used and managed. CTS
facilitates cross-language integration, type safety, and high performance code execution. The CLS
is a specification that defines the rules to support language integration. This is done in such a
way, that programs written in any language (.NET compliant) can interoperate with one another.
This also can take full advantage of inheritance, polymorphism, exceptions, and other features.
For Application objects we can use globally....means there is only one application id will be
created
2. System.Exception vs application.Exceptionm
Ans:
There r 2 important classes in the hierarchy that r derived from System.Exception:
1) System.SystemException -> This class is for exceptions that r usually thrown by the .net
runtime, or which r considered to be of a generic nature and must be thrown by almost any
application. For example, StackOverflowException will be thrown by the .net runtime if it detects
the stack is full. On the other hand, u might choose to throw ArgumentException or it’s
subclasses in ur code, if u detect that a method has been called with inappropriate arguments.
Subclasses of System.SystemException includes classes that represent both fatal and non-fatal
errors.
2) System.ApplicationException-> This class is important, becoz it is the intended base for any
class of exception defined by third parties. Hence, if u define any exceptions covering error
conditions unique to ur application, u should derive these directly or indirectly from
System.ApplicationException
Class B:A
{
public overrid void hi(int a)
}
}
Class A
{
class a()
}
class a(int a)
{
}
}
The difference between char and varchar are in both storage and performance:
1. Storage wise: char columns have fixed length. If the user supplied value
for the column is less than the fixed length defined in the schema, the
column is padded with 0 at end to make the total length fixed. varchar
doesn't have a fixed length thus no padding is needed. But as the result
varchar columns have to store the size of the data together with the column
data, which takes an extra 2 bytes per varchar column.
TINYINT, SMALLINT, INT and BIGINT are all the same in the sense that they are all exact number
data types that use integer data. The difference between these data types are in the minimum
and maximum values that each can contain as well as the storage size required by each data
type, as shown in the following table:
Data Storage
Minimum Value Maximum Value
Type Size
-2^63 (- 2^63 - 1
bigint 8 bytes
9,223,372,036,854,775,808) (9,223,372,036,854,775,807)
Choosing which of these data types to use depends on the value you want to store for the column
or variable. The rule of thumb is to always use the data type that will require the least storage
size. Don't always use INT as your data type for whole numbers if you don't need to. If you
simply need to store a value between 0 and 255 then you should define your column as TINYINT.
Converting from Decimal or Numeric to float can cause some loss of precision. For the Decimal or
Numeric data types, SQL Server considers each specific combination of precision and scale as a
different data type. DECIMAL(2,2) and DECIMAL(2,4) are different data types. This means that
11.22 and 11.2222 are different types though this is not the case for float. For FLOAT(6) 11.22
and 11.2222 are same data types.
What's the difference between SMALLMONEY and MONEY data types and when do I use
them?
MONEY and SMALLMONEY are both monetary data types for representing monetary or currency
values. The differences between these 2 data types are in the minimum and maximum values
Storage
Data Type Minimum Value Maximum Value
Size
-2^63 (- 2^63 - 1
money 8 bytes
922,337,203,685,477.5808) (+922,337,203,685,477.5807)
Both SMALLMONEY and MONEY data types has an accuracy to a ten-thousandths of a monetary
unit. The rule of thumb is to always use the data type that will require the least storage size. If
the monetary value that you will store is less than 214,748.3647 then you should use
SMALLMONEY; otherwise use the MONEY data type.
In SQL Server, there's no boolean data type. The nearest data type that can be used in place of
boolean data is the BIT data type, which is an integer data type that can accept a value of 1, 0 or
NULL value only.
What's the difference between FLOAT and REAL data types and when do I use them?
FLOAT and REAL data types are both approximate number data types for use with floating point
numeric data. Floating point data is approximate; not all values in the data type range can be
precisely represented. The differences between these 2 data types are in the minimum and
maximum values each can hold as well as the storage size required, as specified in the following
table:
For FLOAT data type, the n is the number of bits used to store the mantissa in scientific notation
and thus dictates the precision and storage size and it must be a value from 1 through 53. If not
specified, this defaults to 53. In SQL Server, the synonym for REAL data type is FLOAT(24). If
your data requires only a maximum of 7 digits precision, you can either use the REAL data type
or FLOAT data type with 24 as the parameter (FLOAT(24)).
what is reference parameter? what is out parameters? what is difference these two?
class Program
{
static void Main(string[] args)
{
int a = 0, b, c = 0, d = 0;
Console.WriteLine("a is normal parameter will not affect the changes after the function
call");
Console.WriteLine("b is out parameter will affect the changes after the function call but
not necessary to initialize the variable b but should be initialized in the function ParamTest ");
Console.WriteLine("c is ref parameter will affect the changes after the function call and is
compulsory to initialize the variable c before calling the function ParamTest");
Console.WriteLine("d is used to store the return value");
d = ParamTest(a, out b, ref c);
Console.WriteLine("a = {0}", a);
Console.WriteLine("b = {0}", b);
Console.WriteLine("c = {0}", c);
Console.WriteLine("d = {0}", d);
}
public static int ParamTest(int a, out int b, ref int c)
{
a = 10;
b = 20;
c = 30;
return 40;
}
}
Which methods are used to execute javascript code from code behind file?
RegisterStartupScript and RegisterClientScriptBlock
while(chs.MoveNext())
The compiler automatically translates the field like property into a call like special method called
as 'accessor" . In property there are two accessor and that are used to save value and retrieve
value from the field. The two properties are 'get' and 'set'.
The get property is used to retrieve a value from the field and the set property is used to assign a
value to a field .
ReadWrite Property :- When both get and set properties are present it is called as ReadWrite
Property.
ReadOnly Property :- When there is only get accessor it is called as ReadOnly Property.
WriteOnly Property :- When there is only set accessor, it is called as WriteOnly Property
For example
This will work fine bt what if when you are aware about the value of string variable test.
if test="abc"....
TryParse is a good method if the string you are converting to an interger is not always numeric.
if(!Int32.TryParse(test,out iResult))
{
//do something
}
The TryParse method returns a boolean to denote whether the conversion has been successfull or
not, and returns the converted value through an out parameter.
This is the new feature in C# 3.0. This enable us to declare a variable whose type is implicitly
inferred from the expression used to initialize the variable.
eg.
Because the initialization value (10) of the variable age is integer type of age will be treated as
integer type of variable. There are few limitation of the var type of variables.
They are:
OR
A nested class is any class whose declaration occurs within the body of another class or interface.
What is the best way to add items from an Array into ArrayList?
Use AddRange method of the ArrayList.
string[] arr = new string[] { "ram", "shyam", "mohan" };
arrList.AddRange(arr);
Write a single line of code to create a text file and write contents into it.
System.IO.File.WriteAllText(@"c:\MyTextFile.txt", "MyContents");
First sort the array using Array.Sort and then use Array.Reverse
Eg.
Array.Reverse(number);
How to convert a sentence into Title Case (Capitalize first character of every word)?
For eg:
<object>.Dispose.
Finalize is used to fire when the object is going to realize the memory.We can set a alert message
to says that this object is going to dispose.
What is reflection?
Reflection is the ability to find the information about types contained in an assembly at runtime.
OR
Reflection is the ability to find out information about objects, the application details (assemblies),
its metadata at run-time.
Edited:
See the example: http://www.dotnetfunda.com/articles/article132.aspx
Static constructor is used to initialize static data members as soon as the class is referenced first
time, whereas an instance constructor is used to create an instance of that class with keyword. A
SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
What is SOAP?
Why SOAP?
Today's applications communicate using Remote Procedure Calls (RPC) between objects like
DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and
security problem; firewalls and proxy servers will normally block this kind of traffic.
A better way to communicate between applications is over HTTP, because HTTP is supported by
all Internet browsers and servers. SOAP was created to accomplish this.
WSDL:
WSDL is an XML-based language for describing Web services and how to access them.
Before you continue you should have a basic understanding of the following:
• XML
• XML Schema
If you want to study these subjects first, find the tutorials on our Home page.
What is WSDL?
WSDL is a document written in XML. The document describes a Web service. It specifies the
location of the service and the operations (or methods) the service exposes.
What is Ajax?
The term Ajax was coined by Jesse James Garrett and is a short form for "Asynchronous
Javascript and XML". Ajax represents a set of commonly used techniques, like HTML/XHTML, CSS,
Document Object Model (DOM), and XML/XSLT, Javascript and the XMLHttpRequest object, to
create RIA's (Rich Internet Applications).
Ajax gives the user, the ability to dynamically and asynchronously interact with a web server,
without using a plug-in or without compromising on the user’s ability to interact with the page.
This is possible due to an object found in browsers called the XMLHttpRequest object.
How can you to add JavaScript to a page when performing an asynchronous postback?
Use the ScriptManager class. This class contains several methods like the RegisterStartupScript(),
RegisterClientScriptBlock(),
RegisterClientScriptInclude(),
RegisterArrayDeclaration(),
RegisterClientScriptResource(),
RegisterExpandoAttribute(),
RegisterOnSubmitStatement()
Explain differences between the page execution lifecycle of an ASP.NET page and an
ASP.NET AJAX page?
In an asynchronous model, all the server side events occur, as they do in a synchronous model.
The Microsoft AJAX Library also raises client side events. However when the page is rendered,
asynchronous postback renders only the contents of the update panel, where as in a synchronous
postback, the entire page is recreated and sent back to the browser.
Which control you need to place on the page to show loading image?
Is it compulsory to have Script manager on the page when you are using any control of
ajax control tool kit?
Yes. Page needs to have a script manager for ajax control tool kit controls to work.
Which property needs to be set for script manager control to extend the time before
throwing time out expection if no response is received from the server?
AsyncPostBackTimeout Property needs to set which gets or sets a value that indicates the time, in
seconds, before asynchronous postback time out if no response is received from the server.
The default value of this property is 90 second. We can also set the user defined error message
using asyncpostbackerrormessage property (as shown in above code) for time out.
What is AJAX
AJAX = Asynchronous JavaScript and XML
AJAX is not a new programming language, but a new technique for creating better, faster, and
With AJAX, a JavaScript can communicate directly with the server, with the XMLHttpRequest
object. With this object, a JavaScript can trade data with a web server, without reloading the
page.
AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server,
allowing web pages to request small bits of information from the server instead of whole pages.
The AJAX technique makes Internet applications smaller, faster and more user-friendly.