Feb 26, 2010

Asp. NET Interview Question and Answer

Value Type:

Value types are allocated on the stack just like primitive types in VBScript, VB6 and C/C++. Value

types are not instantiated using new go out of scope when the function they are defined within

returns.

Value types in the CLR are defined as types that derive from system.valueType.

A data type that fully describes a value by specifying the sequence of bits that constitutes the

value‘s representation. Type information for a value type instance is not stored with the instance

at run time, but it is available in metadata. Value type instances can be treated as objects using

boxing.

What is Boxing and unboxing ?

Boxing:

The conversion of a value type instance to an object, which implies that the instance will carry

full type information at run time and will be allocated in the heap. The Microsoft intermediate

language (MSIL) instruction set‘s box instruction converts a value type to an object by making a

copy of the value type and embedding it in a newly allocated object.

Un-Boxing:

The conversion of an object instance to a value type

What is JIT and how is works ?

An acronym for ”just-in-time,” a phrase that describes an action that is taken only when it becomes

necessary, such as just-in-time compilation or just-in-time object activation

What is portabLe executabLe (PE) ?

The file format used for executable programs and for files to be linked together to form executable

programs

What is strong name?

A name that consists of an assembly‘s identityHits simple text name, version number, and culture

information (if provided)Hstrengthened by a public key and a digital signature generated over the

assembly. Because the assembly manifest

contains file hashes for all the files that constitute the assembly implementation, it is

sufficient to generate the digital signature over just the one file in the assembly that contains

the assembly manifest. Assemblies with the same strong name are expected to be identical

What is gLobaL assembLy cache?

A machine-wide code cache that stores assemblies specifically installed to be shared by many

applications on the computer. Applications deployed in the global assembly cache must have a strong

name.

What is difference between constants, readonLy and, static ?

Constants: The value can’t be changed

Read-only: The value will be initialized only once from the constructor of the class. Static: Value

can be initialized once.

What is difference between shared and pubLic?

An assembly that can be referenced by more than one application. An assembly must be explicitly

built to be shared by giving it a cryptographically strong name.

What is namespace used for Loading assembLies at run time and name the methods?

System.Reflection

What are the types of authentication in .net?

We have three types of authentication:

1. Form authentication

2. Windows authentication

3. Passport

This has to be declared in web.config file.

What is the difference between a Struct and a CLass in C# ?

The struct type is suitable for representing lightweight objects such as Point, Rectangle, and

Color. Although it is possible to represent a point as a class, a struct is more efficient in some

scenarios. For example, if you declare an array of 1000 Point objects,

you will allocate additional memory for referencing each object. In this case, the struct is less

expensive.

When you create a struct object using the new operator, it gets created and the appropriate

constructor is called. Unlike classes, structs can be instantiated without using the new operator.

If you do not use new, the fields will remain unassigned and the object cannot be used until all of

the fields are initialized. It is an error to declare a default (parameterless) constructor for a

struct. A default constructor is always provided to initialize the struct members to their default

values.

It is an error to initialize an instance field in a struct.

There is no inheritance for structs as there is for classes. A struct cannot inherit from another

struct or class, and it cannot be the base of a class. Structs, however, inherit from the base

class Object. A struct can implement interfaces, and it does that exactly as classes do.

A struct is a value type, while a class is a reference type.

How big is the datatype int in .NET?

32 bits.

How big is the char?

16 bits (Unicode).

How do you initiate a string without escaping each backsLash?

Put an @ sign in front of the double-quoted string.

What’s the access level of the visibility type internal?

Current appLication.

Explain encapsulation ?

The impLementation is hidden, the interface is exposed.

What data type should you use if you want an 8-bit value that’s signed?

sbyte.

Speaking of Boolean data types, what’s different between C# and C/C++?

There‘s no conversion between 0 and faLse, as weLL as any other number and true, Like in

C/C++.

Where are the value-type variables allocated in the computer RAM?

Stack.

Where do the reference-type variables go in the RAM?

The references go on the stack, whiLe the objects themseLves go on the heap.

What is the difference between the value-type variables and reference-type variables in terms of

garbage collection?

The vaLue-type variabLes are not garbage-coLLected, they just faLL off the stack when they faLL

out of scope, the reference-type objects

are picked up by GC when their references go nuLL.

How do you convert a string into an integer in .NET?

Int32.Parse(string)

How do you box a primitive data type variable?

Assign it to the object, pass an object.

Why do you need to box a primitive variable?

To pass it by reference.

What’s the difference between Java and .NET garbage collectors?

Sun Left the impLementation of a specific garbage coLLector up to the JRE deveLoper, so their

performance varies wideLy, depending on whose JRE you‘re using. Microsoft standardized on their

garbage coLLection.

How do you enforce garbage collection in .NET?

System.GC.CoLLect();

Can you declare a C++ type destructor in C# like >MyClass()?

Yes, but what‘s the point, since it wiLL caLL FinaLize(), and FinaLize() has no guarantees when the

memory wiLL be cLeaned up, pLus, it introduces additionaL Load on the garbage coLLector.

What’s different about namespace declaration when comparing that to package declaration in Java?

No semicoLon.

Asp.net C# and OOPs Question & Answer

What’s the difference between const and readonly?

You can initiaLize readonLy variabLes to some runtime vaLues. Let‘s say your program uses current

date and time as one of the vaLues that won‘t change. This way you decLare pubLic readonLy string

DateT 3 new DateTime().ToString().

What does \a character do?

On most systems, produces a rather annoying beep.

Can you create enumerated data types in C#?

Yes.

What’s different about switch statements in C#?

No faLL-throughs aLLowed.

What happens when you encounter a continue statement inside the for loop?

The code for the rest of the Loop is ignored, the controL is transferred back to the beginning of

the Loop.

What’s the advantage of using System.Text.StringBuilder over System.String? StringBuiLder is more

efficient in the cases, where a Lot of manipuLation is done to the text. Strings are immutabLe, so

each time it‘s being operated on, a new instance is created.

Can you store multiple data types in System.Array?

No.

What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

The first one performs a deep copy of the array, the second one is shaLLow.

How can you sort the elements of the array in descending order?

By caLLing Sort() and then Reverse() methods.

What’s the .NET datatype that allows the retrieval of data by a unique key?

HashTabLe.

What’s class SortedList underneath?

A sorted HashTabLe.

Will finally block get executed if the exception had not occurred?

Yes.

What’s the C# equivalent of C++ catch (A), which was a catch-all statement for any possible

exception?

A catch bLock that catches the exception of type System.Exception. You can aLso omit the parameter

data type in this case and just write catch WX.

Can multiple catch blocks be executed?

No, once the proper catch code fires off, the controL is transferred to the finaLLy bLock (if there

are any), and then whatever foLLows the finaLLy bLock.

Why is it a bad idea to throw your own exceptions?

WeLL, if at that point you know that an error has occurred, then why not write the proper code to

handLe that error instead of passing a new Exception object to the catch bLock? Throwing your own

exceptions signifies some design fLaws in the project.

How’s the DLL Hell problem solved in .NET?

AssembLy versioning aLLows the appLication to specify not onLy the Library it needs to run (which

was avaiLabLe under Win32), but aLso the version of the assembLy.

What are the ways to deploy an assembly?

An MSI instaLLer, a CAB archive, and XCOPY command.

What’s a sateLLite assembLyi

When you write a multilingual or multi-cultural application in .NET, and want to distribute the

core application separately from the localized modules, the localized assemblies that modify the

core application are called satellite assemblies.

What namespaces are necessary to create a LocaLized appLicationi

System.Globalization, System.Resources.

What’s the difference between II comments, I* *I comments and III commentsi

Single-line, multi-line and XML documentation comments.

How do you generate documentation from the C# fiLe commented properLy with a command-Line compiLeri

Compile it with a /doc switch.

What’s the difference between the Debug cLass and Trace cLassi

Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and

release builds.

Why are there five tracing LeveLs in System.Diagnostics.TraceSwitcheri

The tracing dumps can be quite verbose and for some applications that are constantly running you

run the risk of overloading the machine and the hard drive there. Five levels range from None to

Verbose, allowing to fine-tune the tracing activities.

Where is the output of TextWriterTraceListener redirectedi

To the Console or a text file depending on the parameter passed to the constructor.

How do you debug an ASP.NET Web appLicationi

Attach the aspnet_wp.exe process to the DbgClr debugger.

What are three test cases you shouLd go through in unit testingi

Positive test cases (correct data, correct output), negative test cases (broken or missing data,

proper handling), exception test

cases (exceptions are thrown and caught properly).

Can you change the vaLue of a variabLe whiLe debugging a C# appLicationi

Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

ExpLain Inheritance, EncapsuLation, PoLymorphismi

CLass: A class is a template or blueprint that defines an object’s attributes and operations and

that is created at design time.

Ob3ect: An object is a running instance of a class that consumes memory and has a finite lifespan.

Inheritance: Inheritance is the concept of reusing common attributes and operations from a

base class in a derived class.

EncapsuLation: Encapsulation is the process of hiding the details from the client. PoLymorphism:

The meaning of the word polymorphism is something like one name, many forms. Polymorphism is the

ability to call the same method on multiple objects that have been instantiated from different

subclasses and generate differing behaviour.

Abstraction: Abstraction is the practice of focusing only on the essential aspects of an object.

It allows you to selectively ignore aspects that you deem unimprtant to the functionality provided

by the object. A good abstraction only provides as many operations and attributes aas are required

to get the job done.

Interface: It‘s an abstract class with public abstract methods all of which must be implemented inthe inherited classes.

Abstract cLass: A class that cannot be instantiated. An abstract class is a class that must be

inherited and have the methods overridden. An abstract class is essentially a blueprint for a class

without any implementation.

When do you absoLuteLy have to decLare a cLass as abstracti

1. When at least one of the methods in the class is abstract.

2. When the class itself is inherited from an abstract class, but not all base abstract

methods have been overridden.

Why can’t you specify the accessibiLity modifier for methods inside the interfacei

They all must be public. Therefore, to prevent you from getting the false impression that you have

any freedom of choice,

you are not allowed to specify any accessibility, it‘s public by default.

How is method overriding different from method overLoadingi

When overriding a method, you change the behavior of the method for the derived class. Overloading

a method simply involves having another method with the same name within the class.

Can you decLare an override method to be static if the originaL method is non-statici No. The

signature of the virtual method must remain the same, only the keyword virtual is changed to

keyword override.

Can you override private virtuaL methodsi

No. Private methods are not accessible outside the class.

What’s the impLicit name of the parameter that gets passed into the cLass’ set methodi

Value, and it‘s datatype depends on whatever variable we‘re changing.

How do you inherit from a cLass in C#i

Place a colon and then the name of the base class. Notice that it‘s double colon in C++.

Does C# support muLtipLe inheritancei

No, use interfaces instead.

When you inherit a protected cLass-LeveL variabLe, who is it avaiLabLe toi

Classes in the same namespace.

What’s the top .NET cLass that everything is derived fromi

System.Object.

What does the keyword virtuaL mean in the method definitioni

The method can be over-ridden.

Can you decLare the override method static whiLe the originaL method is non-statici

No, you can‘t, the signature of the virtual method must remain the same, only the keyword virtual

is changed to keyword override.Can you override private virtuaL methodsi

No, moreover, you cannot access private methods in inherited classes, have to be protected in the

base class to allow any sort of access.

Can you prevent your cLass from being inherited and becoming a base cLass for some other cLassesi

Yes, that‘s what keyword sealed in the class definition is for. The developer trying to derive from

your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It‘s the

same concept as final class in Java.

Can you aLLow cLass to be inherited, but prevent the method from being over-riddeni

Yes, just leave the class public and make the method sealed.

Why can’t you specify the accessibiLity modifier for methods inside the interfacei

They all must be public. Therefore, to prevent you from getting the false impression that you have

any freedom of choice, you are not allowed to specify any accessibility, it‘s public by default.

Types of PoLymorphismi

1) Compiletime Polymorphism, Early Binding (Method overloading)

2) Runtime Polymorphism, Late Binding(Method overriding through inheritance, Method overriding

through the C# interface)

With runtime polymorphism based on method overriding, the decision as to which version of a method

will be executed is based on the actual type of object whose reference is stored in the reference

variable, and not on the type of the reference variable on which the method is invoked.

Can you inherit muLtipLe interfacesi

Yes, why not.

And if they have confLicting method namesi

It‘s up to you to implement the method inside your own class, so implementation is left entirely up

to you. This might cause a problem on a higher-level scale if similarly named methods from

different interfaces expect different data, but as far as compiler cares you‘re

okay.

You can implement method like Interface1.GetName(), Interface2.GetName() with full qualified method

name.

What’s the difference between an interface and abstract cLassi

In the interface all methods must be abstract, in the abstract class some methods can be concrete.

In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

-Interfaces are closely related to abstract classes that have all members abstract.

- For an abstract class, at least one method of the class must be an abstract method that means it

may have concrete methods.

- For an interface, all the methods must be abstract

- Class that implements an interface much provide concrete implementation of all the methods

definition in an interface or else must be declare an abstract class.

- In C#, multiple inheritance is possible only through implementation of multiple interfaces.

Abstract class can only be derived once.

- An interface defines a contract and can only contains four entities viz methods, properties,

events and indexes. An interface thus cannot contain constants, fields, operators, constructors,

destructors, static constructors, or types.

- Also an interface cannot contain static members of any kind. The modifiers abstract, public,

protected, internal, private, virtual, override is disallowed, as they make no sense in this

context.

- Class members that implement the interface members must be publicly accessible.

How can you overLoad a methodi

Different parameter data types, different number of parameters, different order of parameters.

If a base cLass has a bunch of overLoaded constructors, and an inherited cLass has another bunch of

overLoaded constructors, can you enforce a caLL from an inherited constructor to an arbitrary base

constructori

Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate

constructor) in the overloaded constructor definition inside the inherited class.

What’s the difference between System.String and System.StringBuiLder cLassesi System.String is

immutable, System.StringBuilder was designed with the purpose of having a mutable string where a

variety of operations can be performed.

Does C# support muLtipLe-inheritancei

No, use interfaces instead.

When you inherit a protected cLass-LeveL variabLe, who is it avaiLabLe toi

Classes in the same namespace.

Are private cLass-LeveL variabLes inheritedi

Yes, but they are not accessible. Although they are not visible or accessible via the class

interface, they are inherited.

Describe the accessibiLity modifier “protected internaL“.

It is available to derived classes and classes within the same Assembly (and naturally from the

base class it‘s declared in).

What’s the top .NET cLass that everything is derived fromi

System.Object.

What’s the advantage of using System.Text.StringBuiLder over System.Stringi

StringBuilder is more efficient in cases where there is a large amount of string manipulation.

Strings are immutable, so each time it‘s being operated on, a new instance is created.

Can you store muLtipLe data types in System.Arrayi

No.

What’s a deLegatei

A delegate object encapsulates a reference to a method.

What’s a muLticast deLegatei

It‘s a delegate that points to and eventually fires off several methods

Windows Forms

Can you write a cLass without specifying namespacei Which namespace does it beLong to by defauLtii

Yes, you can, then the class belongs to global namespace which has no name. For commercial

products, naturally, you wouldn‘t want global namespace.



You are designing a GUI appLication with a windows and severaL widgets on it. The user then

resizes the app window and sees a Lot of grey space, whiLe the widgets stay in pLace. What’s the

probLemi

One shouLd use anchoring for correct resizing. Otherwise the defauLt property of a widget on a form

is top-Left, so it stays at the same Location when resized.

How can you save the desired properties of Windows Forms appLicationi

.config fiLes in .NET are supported through the API to aLLow storing and retrieving information.

They are nothing more than simpLe XML fiLes, sort of Like what .ini fiLes were before for Win32apps.

So how do you retrieve the customized properties of a .NET appLication from XML .config fiLei

InitiaLize an instance of AppSettingsReader cLass. CaLL the GetVaLue method of AppSettingsReader

cLass, passing in the name of the property and the type expected. Assign the resuLt to the

appropriate variabLe.

Can you automate this processi

In VisuaL Studio yes, use Dynamic Properties for automatic .config creation, storage and retrievaL.

My progress bar freezes up and diaLog window shows bLank, when an intensive background process

takes over.

Yes, you shouLdIve muLti-threaded your GUI, with taskbar and main form being one thread, and the

background process being the other.

Asp.Net Remoting

What are possible implementations of distributed applications in .NET?
.NET Remoting and ASP.NET Web Services. If we taLk about the Framework CLass Library, noteworthy cLasses are in System.Runtime.Remoting and System.Web.Services.

When would you use .NET Remoting and when Web services?
Use remoting for more efficient exchange of information when you controL both ends of the appLication. Use Web services for open-protocoL-based information exchange when you are just a cLient or a server with the other end beLonging to someone eLse.

What’s a proxy of the server ob3ect in .NET Remoting?
ItIs a fake copy of the server object that resides on the cLient side and behaves as if it was the server. It handLes the communication between reaL server object and the cLient object. This process is aLso known as marshaLing.

What are remotable ob3ects in .NET Remoting?
RemotabLe objects are the objects that can be marshaLed across the appLication domains. You can marshaL by vaLue, where a deep copy of the object is created and then passed to the receiver. You can aLso marshaL by reference, where just a reference to an existing object is passed.

What are channels in .NET Remoting?

ChanneLs represent the objects that transfer the other seriaLized objects from one appLication domain to another and from one computer to another, as weLL as one process to another on the same box. A channeL must exist before an object can be transferred.

What security measures exist for .NET Remoting in System.Runtime.Remoting?

None. Security shouLd be taken care of at the appLication LeveL. Cryptography and other security techniques can be appLied at appLication or server LeveL.

What is a formatter?

A formatter is an object that is responsibLe for encoding and seriaLizing data into messages on one end, and deseriaLizing and decoding messages into data on the other end.

Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters, what are the trade-offs?
Binary over TCP is the most effiecient, SOAP over HTTP is the most interoperabLe.

What’s SingleCall activation mode used for?

If the server object is instantiated for responding to just one singLe request, the request shouLd be made in SingLeCaLL mode.

What’s Singleton activation mode?

A singLe object is instantiated regardLess of the number of cLients accessing it. Lifetime of this object is determined by Lifetime Lease.

How do you define the lease of the ob3ect?

By impLementing ILease interface when writing the cLass code.

Can you configure a .NET Remoting ob3ect via XML file?

Yes, via machine.config and appLication LeveL .config fiLe (or web.config in ASP.NET).

AppLication-LeveL XML settings take precedence over machine.config.

How can you automatically generate interface for the remotable ob3ect in .NET with

Microsoft tools?

Use the Soapsuds tooL.

Main Link For Dot Net

**** .net all effects of trail in live:




***This is a link to conevert to C#.net TO VB.net
http://www.developerfusion.com/tools/convert/csharp-to-vb/

All java Scripts link
http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

***ajax.net action page:
Site:
http://www.dofactory.com/Framework/Framework.aspx

http://www.dofactory.com/Ajax/Source/AjaxSource.aspx?id=AjaxMessageText&file=

Ajax sites download:

http://asp.net/ajax/downloads/

http://blogs.msdn.com/kirti/


Ajax toolkit properties all:
http://asp.net/AJAX/AjaxControlToolkit/Samples/Rating/Rating.aspx



.net material 3tire,web services:
http://www.c-sharpcorner.com/UploadFile/ashok_kp/IntroductionToWebServicesT11252005045531AM/IntroductionToWebServicesT.aspx

.net controls site:

http://demos.devexpress.com/ASPxperienceDemos/PopupControl/Features.aspx

Java scripts:

http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

a great software , update to 2.51 versiom

http://effectmatrix.com/Youtube_video_download_tool/index.htm


A_Programmers_Introduction_to_Visual_Basic.NET.pdf

http://rapidshare.com/files/91385783/A_Programmers_Introduction_to_Visual_Basic.NET.pdf

Applied_Microsoft.NET_Framework_Programming.pdf

http://rapidshare.com/files/91385956/Applied_Microsoft.NET_Framework_Programming.pdf

Apress.dot.NET.

2.0.Interoperability.Recipes.A.Problem.Solution.Approach.Mar.2006.pdf

http://rapidshare.com/files/91386689/Apress.dot.NET.2.0.Interoperability.Recipes.A.Problem.Solution.Approach.Mar.2006.pdf
Apress.Foundations.of.Object.Oriented.Programming.Using.dot.NET.
2.0.Patterns.Oct.2005.pdf

http://rapidshare.com/files/91386979/Apress.Foundations.of.Object.Oriented.Programming.Using.dot.NET.2.0.Patterns.Oct.2005.pdf


ASP.NET_2.0_Unleashed.chm

http://rapidshare.com/files/91388239/ASP.NET_2.0_Unleashed.chm


ASP.NET_for_Developers.pdf

http://rapidshare.com/files/91389149/ASP.NET_for_Developers.pdf


Beginning_Ajax_with_ASP.NET.pdf

http://rapidshare.com/files/91389410/Beginning_Ajax_with_ASP.NET.pdf


Beginning_ASP_.NET_3.5_in_C__2008_Second_Edition.pdf

http://rapidshare.com/files/91390785/Beginning_ASP_.NET_3.5_in_C__2008_Second_Edition.pdf


Beginning_ASP.NET_2.0__Wrox2006__by_Tantanoid.pdf

http://rapidshare.com/files/91391107/Beginning_ASP.NET_2.0__Wrox2006__by_Tantanoid.pdf


Beginning_ASP.NET_3.5_in_C__2008_Second_Edition.pdf

http://rapidshare.com/files/91392565/Beginning_ASP.NET_3.5_in_C__2008_Second_Edition.pdf



Microsoft.Press.Application.Interoperability.Microsoft.Dot.NET.and.J2EE.Dot.Patterns._.Practices.eBo

http://rapidshare.com/files/91392684/Microsoft.Press.Application.Interoperability.Microsoft.Dot.NET.and.J2EE.Dot.Patterns._.Practices.eBo


Pro_.NET_2.0_Code_and_Design_Standards_in_C_.pdf

http://rapidshare.com/files/91393152/Pro_.NET_2.0_Code_and_Design_Standards_in_C_.pdf


Pro_.NET_2.0_Windows_Forms_and_Custom_Controls_in_C_.pdf

http://rapidshare.com/files/91394280/Pro_.NET_2.0_Windows_Forms_and_Custom_Controls_in_C_.pdf


Pro_ADO.NET_2.0.pdf

http://rapidshare.com/files/91394597/Pro_ADO.NET_2.0.pdf


Pro_ASP.NET_2.0_in_C__2005.pdf

http://rapidshare.com/files/91395501/Pro_ASP.NET_2.0_in_C__2005.pdf


Pro_Scalable_.NET_2.0_Application_Designs.pdf

http://rapidshare.com/files/91397861/Pro_Scalable_.NET_2.0_Application_Designs.pdf


Professional_.NET_Framework_2.0.chm

http://rapidshare.com/files/91398772/Professional_.NET_Framework_2.0.chm



Professional_ADO.NET_2_Programming_with_SQL_Server_2005_Oracle_and_MySQL.pdf


http://rapidshare.com/files/91399412/Professional_ADO.NET_2_Programming_with_SQL_Server_2005_Oracle_and_MySQL.pdf


Professional_Web_Parts_and_Custom_Controls_with_ASP.NET_2.0.pdf

http://rapidshare.com/files/91400468/Professional_Web_Parts_and_Custom_Controls_with_ASP.NET_2.0.pdf


SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.001

http://rapidshare.com/files/91402148/SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.001


SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.002

http://rapidshare.com/files/91403458/SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.002


Teach_Yourself_ASP.NET_2.0_in_24_Hours.chm

http://rapidshare.com/files/91404750/Teach_Yourself_ASP.NET_2.0_in_24_Hours.chm
MCTS certification info

ADO.NET QUESTION ANSWER

What is a dataset? 
A dataset is the local repository of the data used to store the tables and disconnected record set. When using disconnected architecture, all the updates are made locally to dataset and then the updates are performed to the database as a batch.
 

What is a data adapter?
A data adapter is the component that exists between the local repository (dataset) and the physical database. It contains the four different commands (SELECT, INSERT, UPDATE and DELETE). It uses these commands to fetch the data from the DB and fill into the dataset and to perform updates done in the dataset to the physical database. It is the data adapter that is responsible for opening and closing the database connection and communicates with the dataset.

 

What is a database connection?
A database connection represents a communication channel between you application and database management system (DBMS). The application uses this connection to pass the commands and queries to the database and obtain the results of the operations from the database.
 

What is a database command?
A database command specifies which particular action you want to perform to the database. The commands are in the form of SQL (Structured Query Language). There are four basic SQL statements that can be passed to the database.
SQL SELECT Statement
This query is used to select certain columns of certain records from a database table.
SELECT * from emp// sql steaments
selects all the fields of all the records from the table name ‘emp’
SELECT empno, ename from emp
selects the fields empno and ename of all records from the table name ‘emp’
SELECT * from emp where empno <>
selects all those records from the table name ‘emp’ that have the value of the field empno less than 100
SELECT * from article, author where article.authorId = author.authorId
selects all those records from the table name ‘article’ and ‘author’ that have same value of the field authorId
SQL INSERT StatementThis query is used to insert a record to a database table.
INSERT INTO emp(empno, ename) values(101, ‘John Guttag’)
inserts a record to emp table and set its empno field to 101 and its ename field to ‘John Guttag’
SQL UPDATE Statement
This query is used to edit an already existing record in a database table.
UPDATE emp SET ename =‘Eric Gamma’ WHERE empno = 101
updates the record whose empno field is 101 by setting its ename field to ‘Eric Gamma’
SQL DELETE Statement
This query is used to delete the existing record(s) from the database table
DELETE FROM emp WHERE empno = 101deletes the record whose empno field is 101 from the emp table
 

What is a data reader?
The data reader is a component that reads the data from the database management system and provides it to the application. The data reader works in the connected manner; it reads a record from the DB, pass it to the application, then reads another and so on.
How do 

different components of ADO.Net interact with each other in disconnected architecture?The Data Adapter contains in it the Command and Connection object. It uses the connection object to connect to the database, execute the containing command, fetch the result and update the DataSet.

What does it mean by Dot Net Framework Data Provider?
Dot Net Framework Data Provider is a set of classes that establishes the database communication between an application and the database management system based on the standards of ADO.Net framework. Different data providers provide specialized and optimized connectivity to particular database management system or to a particular class of DBMS. For example, the MS SQL Server data provider provides the optimized connectivity between dot net application and MS SQL Server DBMS while the OLEDB data provider provides the uniform connectivity between dot net application and the OLEDB databases.






What is ADO.Net?
Most of the today’s applications need to interact with database systems to persist, edit or view data. In .Net data access service is provided through ADO.Net (ActiveX Data Object in Dot Net) components. ADO.Net is an object oriented framework that allows you to interact with database systems. We usually interact with database systems through SQL queries or stored procedures. ADO.Net encapsulates our queries and commands to provide a uniform access to various database management systems.
ADO.Net is a successor of ADO (ActiveX Data Object). The prime features of ADO.Net are its disconnected data access architecture and XML integration.
 
What does it mean by disconnected data access architecture of ADO.Net?
ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the database system and then interact with it through SQL queries using the connection. The application stays connected to the DB system even when it is not using DB services. This commonly wastes the valuable and expensive database resource as most of the time applications only query and view the persistent data. ADO.Net solves this problem by managing a local buffer of persistent data called data set. Your application automatically connects to the database server when it needs to pass some query and then disconnects immediately after getting the result back and storing it in dataset. This design of ADO.Net is called disconnected data architecture and is very much similar to the connection less services of http over the internet. It should be noted that ADO.Net also provides the connection oriented traditional data access services.

 
What does it mean by disconnected data access architecture of ADO.Net?ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the database system and then interact with it through SQL queries using the connection. The application stays connected to the DB system even when it is not using DB services. This commonly wastes the valuable and expensive database resource as most of the time applications only query and view the persistent data. ADO.Net solves this problem by managing a local buffer of persistent data called data set. Your application automatically connects to the database server when it needs to pass some query and then disconnects immediately after getting the result back and storing it in dataset. This design of ADO.Net is called disconnected data architecture and is very much similar to the connection less services of http over the internet. It should be noted that ADO.Net also provides the connection oriented traditional data access services.
 
What does it mean by connected data access architecture of ADO.Net?
In the connected environment, it is your responsibility to open and close the database connection. You first establish the database connection, perform the interested operations to the database and when you are done, close the database connection. All the changes are done directly to the database and no local (memory) buffer is maintained.
 
What's the difference between accessing data with dataset or data reader?
The dataset is generally used when you like to employ the disconnected architecture of the ADO.Net. It reads the data into the local memory buffer and perform the data operations (update, insert, delete) locally to this buffer.
The data reader, on the other hand, is directly connected to the database management system. It passes all the queries to the database management system, which executes them and returns the result back to the application.
Since no memory buffer is maintained by the data reader, it takes up fewer resources and performs more efficiently with small number of data operations. The dataset, on the other hand is more efficient when large number of updates are to be made to the database. All the updates are done in the local memory and are updated to the database in a batch. Since database connection remains open for the short time, the database management system does not get flooded with the incoming requests.
 
What are the performance considerations when using dataset?
Since no memory buffer is maintained by the data reader, it takes up fewer resources and performs more efficiently with small number of data operations. The dataset, on the other hand is more efficient when large number of updates are to be made to the database. All the updates are done in the local memory and are updated to the database in a batch. Since database connection remains open for the short time, the database management system does not get flooded with the incoming requests.
However, since the dataset stores the records in the local buffer in the hierarchical form, it does take up more resources and may affect the overall performance of the application.
 
How to select dataset or data reader?
The data reader is more useful when you need to work with large number of tables, database in non-uniform pattern and you need not execute the large no. of queries on few particular table.
When you need to work on fewer no. of tables and most of the time you need to execute queries on these fewer tables, you should go for the dataset.
It also depends on the nature of application. If multiple users are using the database and the database needs to be updated every time, you must not use the dataset. For this, .Net provides the connection oriented architecture. But in the scenarios where instant update of database is not required, dataset provides optimal performance by making the changes locally and connecting to database later to update a whole batch of data. This also reduces the network bandwidth if the database is accessed through network.
Disconnected data access is suited most to read only services. On the down side, disconnected data access architecture is not designed to be used in the networked environment where multiple users are updating data simultaneously and each of them needs to be aware of current state of database at any time (e.g., Airline Reservation System).

How XML is supported in ADO.Net?
The dataset is represented in the memory as an XML document. You can fill the dataset by XML and can also get the result in the form of XML. Since XML is an international and widely accepted standard, you can read the data using the ADO.Net in the XML form and pass it to other applications using Web Service. These data consuming application need not be the essentially Dot Net based. They may be written with Java, C++ or any other programming language and running on any platform.



 

Asp.NET Important Question And Answer

1) Which of the following languages can be used to write server side scripting in ASP.NET?
a) C-sharp
b) VB
c) C++
d) a and b


2) When an .aspx page is requested from the web server, the out put will be rendered to browser in following format.
a) HTML
b) XML
c) WML
d) JSP

3) The Asp.net server control, which provides an alternative way of displaying text on web page, is
a) <>
b) <>
c) <>

4) The first event to be triggered in an aspx page is.
a) Page_Load()
b) Page_Init()
c) Page_click()

5) Postback occurs in which of the following forms.
a) Winforms
b) HTMLForms
c) Webforms

6) What namespace does the Web page belong in the .NET Framework class hierarchy?
a) System.web.UI.Page
b) System.Windows.Page
c) System.Web.page


7) Which method do you invoke on the Data Adapter control to load your generated dataset?
a) Fill( )
b) ExecuteQuery( )
c) Read( )

8) How do you register a user control?
a) Add Tag prefix, Tag name
b) Add Source, Tag prefix
c) Add Src, Tagprefix, Tagname

9) Which of the following is true?
a) User controls are displayed correctly in the Visual Studio .NET Designer
b) Custom controls are displayed correctly in VS.Net Designer
c) User and Custom controls are displayed correctly in the Visual Studio .NET Designer.

10) To add a custom control to a Web form we have to register with.
a) TagPrefix
b) Name space of the dll that is referenced
c) Assemblyname
d) All of the above

11) Custom Controls are derived from which of the classes
a) System.Web.UI.Webcontrol
b) System.Web.UI.Customcontrol
c) System.Web.UI.Customcontrols.Webcontrol

12) How ASP.Net Different from classic ASP?
a) Scripting is separated from the HTML, Code is interpreted seperately
b) Scripting is separated from the HTML, Code is compiled as a DLL, the
DLLs can be executed on server

c) Code is separated from the HTML and interpreted Code is interpreted separately

13) What's the difference between Response.Write() andResponse.Output.Write()?
a) Response.Output.Write() allows you to flush output
b) Response.Output.Write() allows you to buffer output
c) Response.Output.Write() allows you to write formatted output
d) Response.Output.Write() allows you to stream output

14) Why is Global.asax is used?
a) Implement application and session level events
b) Declare Global variables
c) No use

15) There can be more than 1 machine.config file in a system
a) True
b) False

16) What is the extension of a web user control file?
a) .Asmx
b) .Ascx
c) .Aspx

17) Which of the following is true?
a) IsPostBack is a method of System.UI.Web.Page class
b) IsPostBack is a method of System.Web.UI.Page class
c) IsPostBack is a readonly property of System.Web.UI.Page class

8) The number of forms that can be added to a aspx page is.
a) 1
b) 2
c) 3
d) More than 3


19) How do you manage states in asp.net application
a) Session Objects
b) Application Objects
c) Viewstate
d) All of the above

20) Which property of the session object is used to set the local identifier?
a) SessionId
b) LCID
c) Item
d) Key

21) Select the caching type supported by ASP.Net
a) Output Caching
b) DataCaching
c) a and b
d) none of the above

22) Where is the default Session data is stored in ASP.Net?
a) InProcess
b) StateServer
c) Session Object
d) al of the above

23) Select the type Processing model that asp.net simulate
a) Event-driven
b) Static
c) Linear
d) Topdown

24) Does the EnableViewState allows the page to save the users input on a form?
a) Yes
b) No

25) Which DLL translate XML to SQL in IIS?
a) SQLISAPI.dll
b) SQLXML.dll
c) LISXML.dll
d) SQLIIS.dll

26) What is the maximum number of cookies that can be allowed to a web site?
a) 1
b) 10
c) 20
d) More than 30

27) Select the control which does not have any visible interface.
a) Datalist
b) DropdownList
c) Repeater
d) Datagrid


28) How do you explicitly kill a user session?
a) Session.Close( )
b) Session.Discard( )
c) Session.Abandon
d) Session.End
e) Session.Exit

29) Which of the following is not a member of ADODBCommand object?
a) ExecuteReader
b) ExecuteScalar
c) ExecuteStream
d) Open
e) CommandText

30) Which one of the following namespaces contains the definition for IdbConnection?
a) System.Data.Interfaces
b) System.Data.Common
c) System.Data
d) System.Data.Connection

Feb 10, 2010

Building ASP.NET UserControls

Introduction

If you are Classic ASP programmer or PHP programmer, you probably use SSI include files quite a lot on your web applications and you probably also know that this has worked quite reasonably well for all of you. But the major disadvantages would be maintaining the code once your web projects has grow bigger. Major problem would be to keep up with the HTML opening and closing tags. Its quite hard to debug the code if you are adding some HTML files in your include files and then later on you find that it produce funny result on certain page. There are no visual GUI or IDE that can help you to see the design view. The only way to debug is by viewing the page in the browser. This has taken quite a lot of developer time. The code was also very messy and also you might need to include all your include files in correct order and lots of developer normally will do copy and paste for all their page.

Luckily in ASP.NET technology, this problem has been solved with the introduction of UserControl. UserControl is basically use the same technology like the SSI includes except that it is a self contained objects where you can set the properties,attributes and methods. UserControl also can be designed using Visual Studio design view which allow you to see the layout of your page nicely.

Main

In this article, I will be presenting some simple example of my existing projects that use UserControls.
We will be doing some Header and Footer UserControls that expose some properties and attributes.
Now, let's start writing some code for creating UserControl.

Open Visual Studio 2005, Add New Web Site and Choose to add New UserControl. First one should be named as Header.ascx and second one as Footer.ascx.

If you look at the HTML source for the user control, you see several interesting differences from a standard ASP.NET Web Page
<%@ CONTROL LANGUAGE="C#" AUTOEVENTWIREUP="true" CODEFILE="Header.ascx.cs" I

INHERITS="UserControl_Header" %>
First,notice that the source uses @Control directive rather than @Page directive which a standard Web page would use. Second, notice that unlike a standard ASP.NET Web Page,no other HTML tags such as body,or DIV exists on the control. The web page containing the user control provides the basic HTML tags such as and
tags.In fact if you try to add server side form tags to the user control,ASP.NET will returns an error when the page is served to the clients.

Now, add this code into your Header.ascx
<%@ CONTROL LANGUAGE="C#" AUTOEVENTWIREUP="true" CODEFILE="Header.ascx.cs" INHERITS="Header" %>

<TABLE BORDER="0" WIDTH="100%">

   <TR>

       <TD>

           I am header User Control.TD>

       <TD>

           Today Date is <%=Date %>

       TD>

       <TD>

           Our Phone Number is <%=PhoneNumber %>

       TD>

   TR>

   <TR>

       <TD COLSPAN="3" BGCOLOR=<%=BgColor %>>

           <ASP:MENU ID="Menu1" RUNAT="server" ORIENTATION="Horizontal" WIDTH="100%" BACKCOLOR="#B5C7DE"

                DYNAMICHORIZONTALOFFSET="2" FONT-NAMES="Verdana" FONT-SIZE="0.8em" FORECOLOR="#284E98"

                STATICSUBMENUINDENT="10px">

               <ITEMS>

                   <ASP:MENUITEM TEXT="Home" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Our Products" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Our Features" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="About Us" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Contact Us" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Why Choose Us" VALUE="New Item">ASP:MENUITEM>

               ITEMS>

               <STATICMENUITEMSTYLE HORIZONTALPADDING="5px" VERTICALPADDING="2px" />

               <DYNAMICHOVERSTYLE BACKCOLOR="#284E98" FORECOLOR="White" />

               <DYNAMICMENUSTYLE BACKCOLOR="#B5C7DE" />

               <STATICSELECTEDSTYLE BACKCOLOR="#507CD1" />

               <DYNAMICSELECTEDSTYLE BACKCOLOR="#507CD1" />

               <DYNAMICMENUITEMSTYLE HORIZONTALPADDING="5px" VERTICALPADDING="2px" />

               <STATICHOVERSTYLE BACKCOLOR="#284E98" FORECOLOR="White" />

           ASP:MENU>

       TD>

   TR>

TABLE>





From the code above, you notice that we use lots of server side tags <%=%> in the ascx file. The reason is because all that values is taken from the usercontrol properties and we can set the properties from the hosted user control page. The idea was be able to set and get the properties from the page.
In this example, we can set the background color of the user page, set the title and set the Date.

Now, add this code into Header.ascx.cs
using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;



public partial class Header : System.Web.UI.UserControl

{

   private string sTitle = "Welcome to My Company";

   private string sPhoneNumber = "12345667";

   private string sDate = "12/12/2007";

   private string sBgColor = "white";

   protected void Page_Load(object sender, EventArgs e)

   {



   }

   public string BgColor

   {

       get

       {

           return sBgColor;

       }

       set

       {

           sBgColor= value;

       }

   }

   public string Title

   {

       get

       {

           return sTitle;

       }

       set

       {

           sTitle = value;

       }

   }

   public string PhoneNumber

   {

       get

       {

           return sPhoneNumber;

       }

       set

       {

           sPhoneNumber = value;

       }

   }

   public string Date

   {

       get

       {

           return sDate;

       }

       set

       {

           sDate = value;

       }

   }



}
From the code above, you can see that we provide public get and set methods for all the properties that we use in Header.ascx file. We also provide default properties values for that incase if the UserControl does not override the property value.

Adding UserControl into Page

To add User Controls to the form, you can do it in two ways.
First, would be easy ways, but you need to have Visual Studio.
Open your Visual Studio in design View, and then drag the Header.ascx from SolutionExplorer into your Page. Once you do that, you can see that Visual Studio does all the necessary code for you.

Second way, would be manually code the UserControl in your page.
Add the Register directives as below
<%@ REGISTER src="Header.ascx" TAGNAME="Header" TAGPREFIX="uc1" %>
You can named the TagName and TagPrefix as you like. After that add the UserControl to the location you want on your page. The tag for user control should be like this
<UC1:HEADERS ID="Header1" RUNAT="server" TITLE="Hello Here" BGCOLOR="red"

PHONENUMBER="123455" />
Notice that in the UserControl above, we can define all the properties that we have previously provide public set methods.

You can also set and get the UserControl properties in code behind.
To get and set the UserControl properties, you can use code like this in your code behind
e.g Header1.Title = "Yes";
or Response.Write(Header1.Title);

UserControls is infact an object in your Page. You can add as many usercontrol on your page, or on multiple page. Each individual UserControl you add can have different set of properties and methods you can call.

Conclusion

ASP.NET UserControl is the new way of encapsulate all your code reuse in your web applications. Old way of doing this would be via SSI includes which can be very messy and very hard to maintain if your site grow. ASP.NET UserControl is infact the simplest form of ASP.NET control encapsulation. Because they are the simplest, they are also the easiest to create and use. Essentially user control is a grouping of existing server controls into a single container control. This enables you to group all your reusable part of webpage into UserControl. The basic example would be Login Controls, News Controls, Header Controls and etc.

If However you want to create your own controls from scratch that has the features like ASP.NET Web Server controls (Label,Button,TextBox), then you need to create the controls as Custom Controls. Custom controls is not discussed in this article.

Get current page name

This function can be used to retrieve the current page:s name, i.e default.aspx, hello.aspx or whatever.


public string GetCurrentPageName()
{
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}


By going through System.Web.HttpContext.Current object we are able to have this function in a generic dll or class - and not in each and every page needing to call it.