300+ [LATEST] Asp.net Interview Questions and Answers

Q1. Is There A Method Similar To Response.redirect That Will Send Variables To The Destination Page Other Than Using A Query String Or The Post Method?

Server.Trfer preserves the current page context, so that in the target page you can extract values and such. However, it can have side effects; because Server.Trfer doesnt’ go through the browser, the browser doesn’t update its history and if the user clicks Back, they go to the page previous to the source page.
Another way to pass values is to use something like a LinkButton. It posts back to the source page, where you can get the values you need, put them in Session, and then use Response.Redirect to trfer to the target page. (This does bounce off the browser.) In the target page you can read the Session values as required.

Q2. When Do You Use Executereader, Executenonquery, Executescalar Methods?

If the command or stored procedure that is being executed returns a set of rows, then we use ExecuteReader method.

If the command or stored procedure that is being executed returns a single value then we use ExecuteScalar method.

If the command or stored procedure performs INSERT, DELETE or UPDATE operations, then we use ExecuteNonQuery method.

ExecuteNon Query method returns an integer specifying the number of rows inserted, deleted or updated.

Q3. What Is Postback?

PostBack is the name given to the process of submitting an ASP.NET page to the server for processing. PostBack is done if certain credentials of the page are to be checked against some sources (such as verification of username and password using database). This is something that a client machine is not able to accomplish and thus these details have to be ‘posted back’ to the server.

Q4. What Is Three Tier Architecture?

Three tier architecture typically consists of a client, server and “agent” between them. The agent is responsible for gathering the results and returning a single response to the agent. Such architecture increases performance, reusability and scalability of the application.

Q5. What Is Service Oriented Architecture?

Service oriented architecture is based on services. Service is a unit of some task performed by a service provider in order to satisfy the consumer.

Q6. What Is Reflection?

All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly.

Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes – e.g. determining data type sizes for marshaling data across context/process/machine boundaries.

Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember ) , or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).

Q7. Can We Do Database Operations Without Using Any Of The Ado.net Objects?


its not at all possible.

Q8. Why Cannot We Use Multiple Inheritance And Garbage Collector Paralelly In .net?

.Net doesn’t support the mutiple inheritance, perhaps you may talk about multi-level inheritance.

In the later case, if a class is inherited from another class, at the time of creating instance, it will obviously give a call to its base class constructor (ie bottom – top approach). Like wise the constructor execution is takes place in top down approach (ie. base class constructor is executed and the derived class constructor is executed).

So for GC,  it will collect only when an object does not have any reference. As we see previously, the derived is constructed based on base class. There is a reference is set to be. Obviously GC cannot be collected.

Q9. What Are The Different Row Versions Available In Table?

There are four types of Rowversions.

The current values for the row. This row version does not exist for rows with a RowState of Deleted.

Default :
The row the default version for the current DataRowState. For a DataRowState value of Added, Modified or Current, the default version is Current. For a DataRowState of Deleted, the version is Original. For a DataRowState value of Detached, the version is Proposed.

The row contains its original values.

The proposed values for the row. This row version exists during an edit operation on a row, or for a row that is not part of a DataRowCollection.

Q10. When Do You Absolutely Have To Declare A Class As Abstract (as Opposed To Free-willed Educated Choice Or Decision Based On Uml Diagram)?

When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

Q11. What Is Msil, And Why Should Developers Need An Appreciation Of It If At All?

MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

Q12. Which Command Using Query Analyzer Will Give You The Version Of Sql Server And Operating System?

SELECT SERVERPROPERTY (‘productversion’), SERVERPROPERTY (‘productlevel’), SERVERPROPERTY (‘edition’).

Q13. How To Change The Page Title Dynamically?

‘Declare Protected WithEvents Title1 As System.Web.UI.HtmlControls. HtmlGenericControl
‘In Page_Load Title1.InnerText =”Page 1″

//Declare protected System.Web.UI.HtmlControls.HtmlGenericControl Title1 ;
//In Page_Load Title1.InnerText =”Page 1″ ;

Q14. What Is Boxing And Unboxing?

Boxing is implicit conversion of ValueTypes to Reference Types (Object). UnBoxing is explicit conversion of Reference Types (Object) to its equivalent ValueTypes. It requires type-casting.

Q15. Difference Between Sqlcommand And Sqlcommandbuilder?

  • SQLCommand is used to execute all kind of SQL queries like DML(Insert, update,Delete) & DDL like(Create table, drop table etc),
  • SQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update & delete.

Q16. What Is An Asssembly Qualified Name? Is It A Filename? How Is It Different?

An assembly qualified name isn’t the filename of the assembly; it’s the internal name of the assembly combined with the assembly version, culture, and public key, thus making it unique.

e.g. (“”System.Xml.XmlDocument, System.Xml, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c5 61934e089″”).

Q17. What Is The Use Of Jit ?

JIT (Just – In – Time) is a compiler which converts MSIL code to native code, Because the common language runtime supplies a JIT compiler for each supported CPU architecture, developers can write a set of MSIL that can be JIT-compiled and run on computers with different architectures. However, your managed code will run only on a specific operating system if it calls platform-specific native APIs, or a platform-specific class library.

JIT compilation takes into account the fact that some code might never get called during execution. Rather than using time and memory to convert all the MSIL in a portable executable (PE) file to native code, it converts the MSIL as needed during execution and stores the resulting native code so that it is accessible for subsequent calls. The loader creates and attaches a stub to each of a type’s methods when the type is loaded. On the initial call to the method, the stub passes control to the JIT compiler, which converts the MSIL for that method into native code and modifies the stub to direct execution to the location of the native code. Subsequent calls of the JIT-compiled method proceed directly to the native code that was previously generated, reducing the time it takes to JIT-compile and run the code.

Q18. How Does Vb.net/c# Achieve Polymorphism?

Polymorphism is achieved through virtual, overloaded, overridden methods in C# and VB.NET.

Q19. Will Finally Block Get Executed If The Exception Had Not Occurred?


Q20. How Can I Ensure That Application-level Variables Are Not Updated By More Than One User Simultaneously?

Use the HttpApplicationState’s Lock and UnLock methods.

Q21. Give An Example That Shows How To Execute A Stored Procedure In Ado.net?

  using (SqlConnection ConnectionObject = new SqlConnection())  {  //Specify the name of the stored procedure to execute and the   Connection Object to use.
SqlCommand CommandObject = new SqlCommand("StoredProcedureName", ConnectionObject);
//Specify the SQL Command type is a stored procedure
CommandObject.CommandType = CommandType.StoredProcedure;
//Open the connection
//Execute the Stored Procedure
int RecordsAffected = CommandObject.ExecuteNonQuery();

Q22. What Are The Various Objects In Dataset ?

Dataset has a collection of DataTable object within the Tables collection. Each DataTable object contains a collection of DataRow objects and a collection of DataColumn objects. There are also collections for the primary keys, constraints, and default values used in this table which is called as constraint collection, and the parent and child relationships between the tables. Finally, there is a DefaultView object for each table. This is used to create a DataView object based on the table, so that the data can be searched, filtered or otherwise manipulated while displaying the data.

Q23. How Can I Specify The Relative Path For A File?

Suppose you have following file hierarchy:


And you are on the login.aspx and want your user to navigate to the default.aspx (or testpage.aspx) file. Then you can use

  • Response.Redirect (“../default.aspx”).
  • Response.Redirect (“../Misc/testpage.aspx”).

Q24. How To Enable And Disable Connection Pooling?

For .NET it is enabled by default but if you want to just make sure set Pooling=true in the connection string. To disable connection pooling set Pooling=false in connection string if it is an ADO.NET Connection.

If it is an OLEDBConnection object set OLE DB Services=-4 in the connection string.

Q25. Explain The Use Of Pre-compilation Tool?

ASP.NET 2.0 delivers a new application deployment utility that enables both developers and administrators to precompile a dynamic ASP.NET application prior to deployment. This precompilation automatically identifies any compilation issues anywhere within the site, as well as enables ASP.NET applications to be deployed without any source being stored on the server (one can optionally remove the content of .aspx files as part of the compile phase), further protecting your intellectual property.

Q26. Describe The Difference Between A Thread And A Process?

A Process is an instance of an running application. And a thread is the Execution stream of the Process. A process can have multiple Thread.

When a process starts a specific memory area is allocated to it. When there is multiple thread in a process, each thread gets a memory for storing the variables in it and plus they can access to the global variables which is common for all the thread.

Eg. A Microsoft Word is a Application. When you open a word file, an instance of the Word starts and a process is allocated to this instance which has one thread.

Q27. Can You Explain What Inheritance Is And An Example Of When You Might Use It?

When you want to inherit (use the functionality of) another class.Example: With a base class named Employee, a Manager class could be derived from the Employee base class.

Q28. What Are The Different Index Configurations A Table Can Have?

A table can have one of the following index configurations:

  • No indexes,
  • A clustered index,
  • A clustered index and many nonclustered indexes,
  • A nonclustered index,
  • Many nonclustered indexes.

Q29. Explain Assembly And Manifest?

An assembly is a collection of one or more files and one of them (DLL or EXE) contains a special metadata called Assembly Manifest. The manifest is stored as binary data and contains details like versioning requirements for the assembly, the author, security permissions, and list of files forming the assembly. An assembly is created whenever a DLL is built. The manifest can be viewed programmatically by making use of classes from the System. Reflection namespace. The tool Intermediate Language Disassembler (ILDASM) can be used for this purpose. It can be launched from the command prompt or via Start> Run.

Q30. What Is Foreign Key?

A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.

Q31. Explain The Situations You Will Use A Web Service And Remoting In Projects?

Web services should be used if the application demands communication over a public network and require to work across multiple platforms. Remoting is faster comparatively and hence can be used in .Net components when performance is a high priority. Few applications can also make use of BOTH web services and Remoting to send and receive data not just across multiple platforms but also between .Net applications where performance and speed is a key priority.

Q32. How To Convert Milliseconds Into Time?

dim ts as TimeSpan = TimeSpan.FromMilliseconds(10000) Response.Write (ts.ToString ())

TimeSpan ts = TimeSpan.FromMilliseconds(10000);
Response.Write (ts.ToString ());

Q33. What Is The Standard You Use To Wrap Up A Call To A Web Service?


Q34. Can We Connect Two Dataadapters To Same Data Source Using Single Connection At Same Time?


we can connect two dataadapters to same datasource using single connection at same time.
There is a technology in ado.net 2.0 called MARS usinng Mars in connection string we can do it.

for eg:

cn.ConnectionString = “server=(local); database=employee; integrated security=sspi; Multiple Active Result Sets=True”;

Q35. How To Get The Url Of Page Dynamically?

Use Request.Url property.

Q36. What Methods Are Fired During The Page Load?

  • Init()-when the page is instantiated.
  • Load()-when the page is loaded into server memory.
  • PreRender()-the brief moment before the page is displayed to the user as HTML.
  • Unload()-when page finishes loading.

Q37. What Is Index?

An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes; they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table sc are sometimes unavoidable, but on large tables, sc have a terrific impact on performance.

Q38. Can You Reuse A Sqlcommand Object?


you can reset the CommandText property and reuse the SqlCommand object.

Q39. How Can We Fine Tune The Command Object When We Are Expecting A Single Row ?

Again CommandBehaviour enumeration provides two values SingleResult and SingleRow. If you are expecting a single value then pass “CommandBehaviour.SingleResult” and the query is optimized accordingly, if you are expecting single row then pass “CommandBehaviour.SingleRow” and query is optimized according to single row.

Q40. When Is The Use Of Update_statistics Command?

This command is basically used when a large processing of data has occurred. If a large amount of deletions any modification or Bulk Copy into the tables has occurred, it has to update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly.

Q41. What Is The Best Way To Output Only Time And Not Date?

Use DateTime as follows VB.NET


Q42. .net Assembly?

This article explains .Net assembly, private and shared assembly, satellite assemblies, resource-only assembly, ResourceManager class, strong name, global assembly cache.

Q43. How To Find The Count Of Records In A Dataset?


we can get count of the records.

Q44. What Is Managed And Unmanaged Code?

The .NET framework provides several core run-time services to the programs that run within it – for example exception handling and security. For these services to work, the code must provide a minimum level of information to the runtime. i.e., code executing under the control of the CLR is called managed code. For example, any code written in C# or Visual Basic .NET is managed code. Code that runs outside the CLR is referred to as “unmanaged code.” COM components, ActiveX components, and Win32 API functions are examples of unmanaged code.

Q45. How Do You Update A Dataset In Ado.net And How Do You Update Database Through Dataset?

Update a dataset:

  Dataset ds = new dataset();  SqlDataAdapter adp = new SqlDataAdapter(Query,connection);  Adp.fill(ds);  Again you can add/update Dataset as below  SqlDataAdapter adp1 = new SqlDataAdapter(Query1,connection);  Adp1.fill(ds);

Update database through dataset.

  SqlCommandBuilder mySqlCommandBuilder = new  SqlCommandBuilder(mySqlDataAdapter);  Foreach(datarow dr in ds.table[0].rows)  {  Dr[“column Name”] = “value”;  mySqlDataAdapter.Update(ds);  }

Q46. What Does The “enableviewstate” Property Do? Why Would I Want It On Or Off?

It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.

Q47. How Do We Update And Delete Data In A Gridview? Datakeynames Property In .net?

The best way to Update or Delete a record in a GridView control is to include a CheckBox column and a Submit Button.

The GridView has its own Delete and Edit functionality. If the GridView is populated with data using an SqlDataSource, checkout the wizard that comes along with the SqlDataSource. It may be used to automatically create an SQL Delete command and specify the delete parameters.

The DataKeyNames property of the GridView is set to a field name of the Table.

Q48. How Can We Save All Data From Dataset?

Dataset has “Accept Changes” method, which commits all the changes since last time “Accept changes” has been executed.

Q49. 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 C


just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Q50. What Are The Advantages Of Using Sql Stored Procedures Instead Of Adhoc Sql Queries In An Asp.net Web Application?

Better Performance : As stored procedures are precompiled objects they execute faster than SQL queries. Every time we run a SQL query, the query has to be first compiled and then executed where as a stored procedure is already compiled. Hence executing stored procedures is much faster than executing SQL queries.

Better Security: For a given stored procedure you can specify who has the rights to execute. You cannot do the same for an SQL query. Writing the SQL statements inside our code is usually not a good idea. In this way you expose your database schema (design) in the code which may be changed. Hence most of the time programmers use stored procedures instead of plain SQL statements.

Reduced Network Traffic : Stored Procedures reside on the database server. If you have to execute a Stored Procedure from your ASP.NET web application you just specify the name of the Stored Procedure. So over the network you just send the name of the Stored Procedure. With an SQL query you have to send all the SQL statements over the network to the database server which could lead to increased network traffic.