In this tutorial, I’m going to post common and frequently asked technical interview questions in .net sql oops with answers for fresher as well as experience developers. I also wrote many other tutorials on Interview Questions, Asp.net, SQL Server, OOP Concepts as well as Top 10 OOPS Concepts in details. I recommend you to read those tutorials, I’m sure, you’ll enjoy it!
It’s very difficult to predict what interviewer will ask during interview, right?
I think so, but I can assure that following are the best list of possible technical interview questions that I’d faced during my job interviews and also I asked as an interviewer in my professional carrier.
Interview Questions in .Net: Asp.net, C#, SQL Server, OOPS Concepts
Here is the list of best 100+ ever green technical interview questions in .net you must read and prepare for your upcoming interview.
Ans: Mainly all controls are accessible in Page_Init event except “ViewState” because it doesn’t fully loaded during this event. The Page_Load event guarantees that all the controls are fully loaded and ready to use.
Ans: The IsPostBack property of “Page” object is used to identify that the Page is Post Back. Here is the example:
//Page is Post Back
//Page is Not Post Back
Ans: ASP stands for Active Server Pages, also known as Classic ASP which is Microsoft’s server-side technology and used to create dynamic and user-friendly web pages.
Asp.net was developed by Microsoft to allow programmers to build dynamic web sites, web applications or web services. It is an open source server-side web application framework designed for Web development to produce dynamic web pages.
The main difference between ASP and ASP.NET is that ASP is Interpreted Language because ASP uses VBScript; whereas ASP.NET is Compiled Language because ASP.NET uses .NET Languages like C#, Vb.net, which are compiled to MSIL (Microsoft Intermediate Language).
Ans: The lifespan of items stored in ViewState lives until the current page expiration including current page post backs. When user requests another page, the previous page data are no longer available. In short, we can say that the lifespan for items stored in ViewState exists till your current page exists.
Ans: It depends on different point of views. There are many of saying that .NET is Platform Independent, Partially Dependent or Platform Dependent. But in my opinion, .NET is Platform Dependent because it needs .NET Framework and Windows OS to run your application.
Ans: The System.Web.UI.Control class is used for all the web server control.
Ans: The ViewState is a feature that is used by ASP.NET page framework to persist the page and server control values between round trips or post backs.
The ViewState information is stored in the HTML hidden fields. It is automatically used by the ASP.NET page framework to persist information that must be preserved between post backs. You can also use ViewState to store application data that is specific to a page, like this:
ViewState["testVS"] = txtID.Text;
//Get the value from ViewStete
if (ViewState["testVS"] != null)
txtID.Text = ViewState["testVS"].ToString();
Ans: When you create website from Visual Studio, the App_Code folder will automatically created in the website root directory, otherwise you need to add it by right clicking on the project. We can use it to store the files that we want to use in our website, like common classes, text files, pdf files, email templates, reports etc.
Ans: The DataSet has read/write access, we can update records; whereas DataReader has read-only access, we can’t update records.
The DataSet supports both forward and backward scanning of data; whereas DataReader supports forward-only scanning of data. Read More
Ans: A DataSet contains a collection of one or more database tables which resides in-memory; whereas A DataTable contains a single database table which resides in-memory.
A DataSet has a collection of data tables; whereas A DataTable has a collection of rows and columns. Read More
Ans: If you want to automatically post back page when any event raised, you need to set the AutoPostBack property of the asp.net control to True as follows.
Ans: Following are the two common ways to pass the values from one page to another page.
Ans: The SQL Injection Attack is a technique of “insertion” or “injection” of a SQL queries via webpage or web form input controls. SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands. It means altering SQL commands into SQL statements, and modifies database tables or data with using SQL Statements like Insert, Update or Delete.
We can prevent SQL Injection Attack by using Parameterized SQL Statements. You can get more details with step-by-step guide and example by go through the Read More link. Read More
Ans: A String is “immutable”, meaning that once you created string object then you can’t modify it; whereas A StringBuilder is “mutable”, meaning that once you created string builder object then you can modify or append without creating a new instance for every time.
In String, Any operation that appears to change the string, it creates a new instance of string type in memory; whereas In StringBuilder, Any operation that appears to modify or append new string, it doesn’t create a new instance of string type in memory. Read More
Ans: Technically there is no difference between both of them. In general, string is an alias for System.String. It’s same like int and System.Int32. You can get more details by go through the below link in detail with example code. Read More
Ans: The DataAdapter is a part of ADO.NET Data Provider. It provides the communication between the DataSet and DataSource.
We can use DataAdapter in combination with the DataSet objects for data access and manipulation capabilities. The DataAdapter uses the SELECT statement to FILL a DataSet or DataTable and other DML statements like INSERT, UPDATE, and DELETE to make modification to DataSource.
Ans: The Fill() method of DataAdapter is use to fill or load the data to DataSet or DataTable, like da.Fill(dt). If you want to check complete example of insert, update, delete including this method, please check here.
Ans: The IIS stands for Internet Information Services which is created by Microsoft to provide Internet based services to your ASP.NET web applications. It is use to host your web applications on the server. It makes your local computer to work as a web server which provides functionality to deploy one or more web applications on the server.
Ans: The ExecuteReader is generally used to get or read data from result set so it’s appropriate with SELECT Command.
The ExecuteNonQuery is generally used when we want to perform any operation on result set so it’s appropriate with INSERT, UPDATE, and DELETE Command.
The ExecuteScalar is generally used when we need only first value of result set or aggregate functions like SUM, COUNT, and AVG etc in SELECT Command. Read More
Ans: The ExecuteScalar returns the first column of the first row from the result set returned by the query, additional rows and columns will be ignore from the result set. It will return null reference if result set is empty.
Ans: The ExecuteNonQuery returns int value as no of row(s) affected. For example, When you are inserting records, you can see “1 row(s) affected”, “5 row(s) affected” etc.
Ans: The User-Defined Function can be used in SQL statements anywhere in the WHERE, HAVING, or SELECT section; whereas the Stored Procedure cannot be used like this, we can use EXEC statement to execute stored procedure. Following are some other differences between them:
- Stored Procedure:
– It can be used to Read and Modify data
– It cannot be used to create constraints while creating a table
– It can return 0 or n number of values; and which is OPTIONAL
– It can have “Input” as well as “Output” parameters
– It supports Transaction Management
– It cannot be called from Function
– It can allow SELECT as well as DML statements such as INSERT, UPDATE, or DELETE
– We can use try-catch block to handle exception
- User-Defined Function:
– It can only Read data
– It can be used to create constraints while creating a table
– It can only return 1 value; and which is MENDATORY
– It can only have “Input” parameters
– It does not support Transaction Management
– It can be called from Stored Procedures
– It can only allows SELECT statement under function
– We cannot use try-catch block in a function to handle exception
Ans: You can get and use connection string this way but what if you had specified your connection string in Web.config and want to get from Web.config file? You can do this by using following single line of code, like this.
string con = ConfigurationManager.ConnectionStrings["mystring"].ConnectionString;
//For Vb.net: Include Namespace – Imports System.Configuration
Dim con As String = ConfigurationManager.ConnectionStrings("mystring").ConnectionString
Ans: A PRIMARY KEY constraint is a unique identifier for a row within a database table. It ensures that all the records have their own distinct values. Primary key constraints don’t allow NULL values, so you guaranteed that each record has its own unique populated value.
A UNIQUE KEY constraint enforces the entity integrity and the uniqueness of the values in a set of columns; so no duplicate values are entered.
On the other hand, FOREIGN KEY constraints are used to enforce referential integrity. A Foreign Key in one table points to a “primary key” or “unique key” on another related database table. It prevent actions that would change rows with foreign key values when there are no primary keys in related table with that same value.
Ans: The QueryString is use to send the one page information and values to another page on the server. If you want to check the example, you can see complete querystring example to pass information between pages here.
– No external server resources are required so no extra overhead on the server
– Supported by all the browsers without having issue
– We don’t need to put extra efforts in existing code so it is easy to use
– All the attributes and values are visible to the end user, which leads to security threads
– There is a limit to a URL length of 255 characters
Ans: A PRIMARY KEY is also a UNIQUE KEY internally, but a primary key cannot allow NULL values; whereas UNIQUE KEY allows a single NULL value but does not allows multiple NULL values over the columns. Following are some other differences between them:
- Primary Key:
– A primary key can be only once in a table
– A primary key never allow NULL values
– A primary key is a unique key identifier and cannot be NULL and must be UNIQUE
- Unique Key:
– A unique key can be more than once in one table
– A unique key can allow NULL values but not multiple NULL values
– A unique key can be NULL and may not be UNIQUE
– A unique key cannot be a candidate key
Ans: A NOT NULL constraint enforces that the column will not allow or accept NULL values. It is used to enforce domain integrity.
Ans: The Microsoft .NET architecture is the programming model for the .NET platform. The .NET Framework provides a managed execution environment, simplified development and deployment and integration with a wide variety of programming languages.
The .NET Framework has two key parts:
- Framework Class Library (FCL): The .NET Framework Class Library is a comprehensive, object-oriented collection of reusable types that you can use to develop applications. The .NET Framework class library includes ADO.NET, ASP.NET, and Windows Forms. It has a collection of 7000+ classes and data type that enable .NET applications to access databases, read & write files, processing XML, GUI, drawing, web services and many more. Some of the examples are System.Data, System.Web, System.SqlClient etc.
- Common Language Runtime (CLR): The CLR is the execution engine for .NET applications & servers as the interface between .NET applications and the operating system. Following are the key features of the CLR:
– Loads & execute code, which includes conversion of intermediate language to native machine code
– Separates process and memory
– Memory and Objects Management
Ans: When a page is requested, it is loaded into the server memory, processed and sent to the browser. Then it is unloaded from the memory. At each of this steps, methods and events are available, which could be overridden according to the need of the application. In other words, you can write your own code to override the default code.
When we execute an ASP.NET Webpage, it passes through the following stages which we can call “Page Life Cycle”:
- Page Request: When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled or whether a cached version of the page can be sent in response without running the page. The page request done before the page life cycle starts.
- Start: In this stage, the Request and Response objects are set. If the request is an old request or post back, the IsPostBack property of the page is set to true. The UICulture property of the page is also set.
- Initialization: In this stage, the page initialize and the control’s UniqueID property are set.
- Load: In this stage, if the current request is a post back, control properties are loaded with information recovered from view state and control state.
- Validation: In this stage, if all server controls on the webpage validates and runs successfully, the IsValid property of the page is set to “true” (which let you to post data on the server) else set to “false” (which prevent you to post data on the server).
- Postback Event Handling: In this stage, if the request is a post back, the related event handler is called.
- Rendering: Before rendering, ViewState is saved for the page and all controls. During the rendering stage, the page calls the “Render” method for each control, providing a text writer that writes its output to the OutputStream object of the page’s Response property.
- Unload: In this stage, the rendered page is sent to the client and page properties, such as Response and Request are unloaded and all cleanup done.
Ans: At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.
Following are the page life cycle events:
- PreInit: The PreInit is the first event in page life cycle. It checks the IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls and gets and sets profile property values. This event can be handled by overloading the OnPreInit method or creating a Page_PreInit handler.
- Init: The Init event fires when the page is initializing.
- InitComplete: The InitComplete event fires when all the controls turn on view state tracking.
- LoadViewState: The LoadViewState event fires when the view state is loading.
- LoadPostData: The LoadPostData event fires when the post back data is processing.
- PreLoad: The PreLoad event fires after the page loads view state for itself and all controls, and after it processes post back data that is included with the Request instance.
- Load: The Load event fires when the page is loading.
- Control events: Use these events to handle specific control events, such as a Button control’s Click event or a TextBox control’s TextChanged event.
- LoadComplete: The LoadComplete event fires at the end of the event-handling stage. When the loading process is completed, control event handlers are run and page validation takes place. This event can be handled by overloading the OnLoadComplete method or creating a Page_LoadComplete handler.
- PreRender: The PreRender event fire just before the output is rendered. By handling this event, pages and controls can perform any updates before the output is rendered.
- PreRenderComplete: The PreRenderComplete event fires just after each data bound control whose DataSourceID property is set calls its DataBind method.
- SaveStateComplete: The SaveStateComplete event fires after view state and control state have been saved for the page and for all controls. Any changes to the page or controls at this point affect rendering, but the changes will not be retrieved on the next post back.
- Render: Actually Render is not an event; but at this stage, the Page object calls this method on each control. All the server controls have a Render method that writes out the control’s markup to send to the browser.
- Unload: The Unload event fires when the page is destroying the instances of the server controls.
Ans: C is a Procedural-Paradigm Language; whereas C++ is a Multi-Paradigm Language, which means procedural, functional as well as object oriented programming language.
Mapping between Data and Function is difficult and complicated in C; whereas In C++, Mapping between Data and Function can be done using “Objects”. Read More
Ans: A DEFAULT constraint is used to add values into a column when values were omitted. It will take the default value (which we can specify during table creation) and insert into that field when no value is inserted for that field. The DEFAULT values can be in form of “integer”, “bool” or “datetime” fields but cannot be defined on TIMESTAMP and IDENTITY columns.
Ans: An Object is a real-world entity that keeps together property states and behaviors. To see an example, Read More from here.
Ans: A Class is a collection of objects and represents description of objects that share same attributes and actions. It contains characteristics of the objects such as objects attributes, actions or behaviors. To see an example, Read More from here.
Ans: A Method is an object’s behavior. To see an example, Read More from here.
Ans: A DELETE command removes the rows from a table on the basis of the condition that we provide within WHERE clause; whereas a TRUNCATE command will remove all of the rows from a table. A DELETE command is a DML statement; whereas a TRUNCATE command is a DDL statement.
TRUNCATE command “Resets the IDENTITY Field” of the table while removing all the rows from the table but the table columns, constraints, indexes, permissions, and structures remains as it is.
In DELETE command we can do rollback; whereas In TRUNCATE command we cannot do rollback.
Note: You cannot use TRUNCATE statement on a table which is referenced by a FOREIGN KEY constraint. If you want to retain the IDENTITY Field counter, then you can use DELETE command. If you want to remove table definition, data, and its structure, you can use DROP command.
Ans: When a browser requests .aspx file, then the server returns a response which is rendered into a HTML string. Actually at that time all of the server controls are converted into HTML control format because web browsers doesn’t understand the server controls; they only understand HTML strings to display results.
Ans: An Encapsulation is the process of keeping or enclosing one or more items within a single physical or logical package. In object oriented programming methodology it prevents access to implementation details. To see an example, Read More from here.
Ans: The MetaDescription and MetaKeyword are the two properties introduced in Page Class in ASP.NET 4.0 Onwards. To see an example, Read More from here.
Ans: The Authentication is the process of validating the identity of a user; whereas Authorization is the process of granting access privileges to resources or tasks within an application.
Ans: An Abstraction is the process of providing only essential information to the outside real world and hiding overall background details to present an object. It relies on the separation of interface and implementation. To see an example, Read More from here.
Ans: An Information Hiding concept restricts direct exposure of the data. Data is accessed indirectly using safe mechanism, methods in case of programming object. Follow the example given in Abstraction.
Ans: An Inheritance in OOP allows us to create a new class using an existing one meaning extending one class to another. The main advantage of extending classes is that it provides a convenient way to reuse existing fully tested code in different context thereby saving lots of time with existing coding and its model style. To see an example, Read More from here.
Ans: The Custom User Controls are the controls that are defined by developers. These controls are a mixture of custom behavior and predefined behavior. These controls works similar to other web server controls.
The @Register directive is used to register a custom server control to a webpage.
<%@ Register TagPrefix="myASP" TagName="myControl" Namespace="MyApp.Controls"
//You can use like this in your .aspx page..
Ans: Following are the difference between both of them:
- Abstract Class:
– Abstract class does not support multiple inheritance
– Abstract class contains Data Member
– Abstract class contains Constructors
– An abstract class Contains both incomplete (abstract) and complete member
– An abstract class can contain access modifiers for the subs, functions, properties
– Only Complete Member of abstract class can be Static
– Interface can support multiple inheritance
– Interface doesn’t contains Data Member
– Interface doesn’t contains Constructors
– An interface contains only incomplete member (signature of member)
– An interface cannot have access modifiers by default everything is assumed as public
– Member of interface cannot be Static
Ans: The word Polymorphism means having many forms. Generally, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. To see an example, Read More from here.
Ans: It allows multiple functions to exist with same name with different signature or parameters. For example, if you take a “bike” as an example, it has a function “start” with two forms that is “Cell Start” or “kick Start”. To see an example, Read More from here.
Ans: It means changing the behavior of the methods of a base class in derived class by overriding the base class methods. For example, if “Base” is a base class with “Calculate” method and class “Derive” inherits class “Base”, thus derives method “Calculate” of class “Base”. The behavior of “Calculate” in class “Derive” can be changed by overriding it. To see an example, Read More from here.
Ans: The MailMessage and SmtpMail classes of System.Net.Mail are used to send an email from your ASP.NET webpage. You also need to create an object of the SmtpClient class to set the server name, port, and credentials. To see an example, Read More from here.
Ans: Validation controls are responsible to validate the data of an input controls. When we use validation control to any specific web server control, it performs the validation on client-side (also if you want to do server-side validation using these validation control) and displays an error message to user with appropriate message to correct the filled details, in case of the validation fails. Following are the available validation server controls to validate web form.
- RequiredFieldValidator: This checks if control contains data or not.
- RegularExpressionValidator: This checks if entered data matches a specific format, such as Email, Numeric, and Phone Number etc.
- CustomValidator: This checks the data entered using a client-side script or a server-side code.
- CompareValidator: This validation control ensure that the values in two different web server controls are matched or not.
- RangeValidator: This checks if entered data is according to the range of two values that is specified in MinimumValue and MaximumValue property of this validation control.
- RangeValidator: This allows user to display the summary of errors at one place in detail.
Ans: The Page.Validate() method is used to force all the validation server controls to run and to perform validation.
Ans: There might be more than one Web.config files for a single project depending on the hierarchy levels of the project folders so we can add mostly one Web.config file for each folder hierarchy level.
Ans: A Boxing is a process of converting the value type into reference type; whereas an Unboxing is a reverse process of it means converting reference type to value type.
int stackVar = 12;
// Boxing = int is created on the "Heap" (means reference type)
object boxedVar = stackVar;
// Unboxing = boxed int is unboxed from the heap and assigned to an int stack variable
int unBoxed = (int)boxedVar;
Ans: A Value Type stores its contents in memory allocated on the stack. When you created a “value type”, a single space in memory is allocated to store the value and that variable directly holds a value; whereas a Reference Types are used by a reference which holds a reference or address to the object but not the object itself because reference types represents the address of the variable rather than the data itself, assigning a reference variable to another doesn’t copy the data.
Examples of reference types are Classes, Objects, Arrays, Indexers, and Interfaces etc; on the other hand, Examples of reference types are Predefined datatypes, structures, enums etc.
int intStack = 5;
//Here the space required for the 5 strings array which is allocated on the "Heap"
string arrHeap = new string;
Ans: The GridView is a web control; whereas the DataGrid is a windows control.
– In GridView control, you can add paging, sorting, or editing capabilities with enabling simple gridview’s property
– GridView has “EditTemplates” template to enable inline editing
– In DataGrid control, we need to add events for paging, sorting, or editing capabilities
– DataGrid does not have “EditTemplates” template to enable inline editing
Ans: When web application is too complex, then there is possibility that multiple developers can work on same modules to speed up development process. So in this situation instead of defining an entire class at once if becomes more difficult to implement as well as understand, so we can split or divide the definition into multiple classes by using “partial” keyword.
At compile or runtime, a compiler will group all the partial classes together and treat them as a single class. There are a several advantages to use partial classes, such as developers can work on different parts of the classes from different places without needing to share same physical files. Following is the simple example to understand the concept of partial class:
public void GetStudentDetails()
//developer is working on student details module
//some other function for same modules..
public partial class student
public void GetStudentResults()
//developer is working on student results module
//some other function for same modules..
Ans: The Cookie is a small text file on the client machine either in the client’s file system or memory of the client browser session. Cookies are not good for sensitive data. Moreover, Cookies can be disabled on the browser so we can’t rely on cookies for the state management.
In other words, Cookie is a lightweight executable program which the server posts to client’s machines. That includes the identity of the user at the first visit of the specific website and on second visit cookie is used to validate the user for their authenticity. This is not the only use of Cookie but there are several others. The Cookie.Discard property is set to “true” means Cookie is turn off for a webpage so it instructs the client application not to save the Cookie on the user’s machine.
The values of a Cookie can be transferred between the user’s request and the server’s response. The default timeout for the Cookie is 30 minutes.
Ans: The Session object stores information about, or change settings for a user session. It is used for State Management in ASP.NET. A Session starts when the browser first request a resources from within the application; and ends when either browser closed or session timeout has been expired.
The default timeout for the Session is 20 minutes but you can change it from Web.config file or override session timeout from IIS settings.
Ans: Yes, we can change the default session timeout from Web.config file. The session timeout is specified in the Web.config file within sessionstate element. You can change the session timeout setting by changing the value of timeout attribute of sessionstate element in Web.config file, like this:
Ans: The Web.config file contains configuration setting for a web application or project, such as Database Connections, Error Page Settings, Session States, Error Handling, HttpHandlers, Security like Authorization and Authentication, Culture Specific Settings etc.
Ans: The Global.asax file is used to execute the application-level events and sets the application-level variables. It contains application-level events, such as Application_Error, Application_Start, Application_End, Session_Start, Session_End etc. You can also add custom event that is supported by Global.asax file.
Ans: In the relational database design, the process of organizing data to minimize redundancy is called “Normalization”. It usually involves dividing data into different tables and defining relationships between the tables. The key feature of the Normalization is to eliminate the data redundancy and ensure the data dependency.
On the other hand, the process of attempting to optimize the performance of a database by adding redundant data is called “De-normalization”. It is sometimes necessary because current database management systems implement the relational model poorly. The key feature of the De-normalization is to move from higher to lower normal forms of database modeling in order to speed up database access.
Ans: A Stored Procedure is a set of SQL statements that have been previously created and stored into the SQL server database to perform some operation, such as retrieving result set from tables, insert, update, delete data etc. You can also use it to backup a database or perform other maintenance tasks on regular intervals.
It can accept input parameters so that a single stored procedure can be used several times over that network by several clients using different input data.
– It can reduce network traffic; results in improved performance of website
– It provides a public interface to a database
– Group of all queries at the same location, making it easier for DBAs to see how the database is queried and optimize it accordingly.
– Security against SQL Injection
– Because scripts are in one location, updates and tracking of dependencies based on schema changes becomes easier
– Limited Coding Functionality
– Any data errors in handling Stored Procedures are not generated until runtime
– It is very difficult to debug Stored Procedure
– It is not efficient to use when we deal with complex logic
– If more than one application are using the same database server very frequently, it can increase the load on server so that application becomes slow.
Note: In my opinion, We can use stored procedures to encapsulate complex queries, such as complex joins, and complex conditions with “WHERE” clause etc but don’t use Stored Procedures for complex application or website logic even don’t try Stored Procedures for CRUD operations with complex logic. So, Stored Procedures should be used in a minority of cases rather than be the standard tool for all queries in an application or website.
Ans: A Trigger is a special type of SQL procedure that initiates an action when an event like INSERT, UPDATE, or DELETE occurs on an database table objects. A trigger cannot be called or executed directly; DBMS automatically fires the trigger as a result of a data modification to the associated table or in the case of DDL triggers to a DDL event in the database. There are 2 types of triggers:
1) DML Trigger – It can be form of Instead of Trigger and After Trigger. The Instead of Triggers are fired in place of the triggering action such as an INSERT, UPDATE, and DELETE; whereas the After Triggers execute after the triggering action such as an INSERT, UPDATE, and DELETE.
2) DDL Trigger – The DDL Trigger are fired against DDL statements like DROP, CREATE, and ALTER table. These types of triggers are always After Triggers.
Ans: Triggers are similar to the stored procedures in that both consist of procedural logic that is stored at the database level to perform some action with database objects. The Stored Procedures are “explicitly executed” by invoking a call to the procedure; whereas the Triggers are “implicitly executed” by any events. In addition, triggers can also execute stored procedures.
Ans: A view can be used to retrieve data as well as update or delete rows. It can be thought of a stored query which is accessible as a “virtual table”. There are several key features of creating a view, few of them are:
– It provides a security mechanism which restricts users to a certain subset of data
– It provides a feature for developers to customize how users can logically view the data
Ans: The Response.Write() is used to write the normal output; whereas the Response.Output.Write() is used to write the formatted output.
Ans: The Orientation property of the Menu Control sets the menu display layout on the webpage, either “horizontal” or “vertical” display. To see an example, Read More from here.
Ans: The Response.Redirect method is used to redirect a webpage, like following example.
Ans: The State Management is used to store the information of all the web server and user requests. It also used to trace the information or data that affect the state of the applications. Following are the two ways to maintain a state in ASP.NET website.
- Client-Based State Management: This type of state management maintains the information on the client’s machine using following objects.
- Server-Based State Management: This type of state management maintains the information on the server using following objects.
Ans: The Content-page is a child page that can be inherited by a Master-page. The Content-page does not have complete HTML source code; whereas the Master-page has complete HTML source code inside its source file. In short, we can say that master page contains full html markup code that is used to display data to the users on the web browser.
Ans: The Login Controls use the Membership system to authenticate a user credentials for a web application. The Login Controls are built-in controls in ASP.NET for providing login functionalities to website or web application. Following are the common controls available that are available within a login control.
- Login Control: It provides a gui interface for user authentication. It consists of a set of controls, such as TextBox, Label, Buttons etc.
- ChangePassword Control: It provides a gui interface and functionalities to change user password.
- LoginView Control: It provides appropriate information to different users according to the user’s status.
- LoginStatus Control: It shows a login link to users, who are not authenticated and logout link, who are authenticated.
- CreateUserWizard Control: It provides a gui interface to the user to register for the website or web application.
- LoginRecovery Control: It allows users to get back password through an email, if they forget.
- LoginName Control: It displays a user name, if the user logged in.
Ans: The PlaceHolder Control acts as a container for those controls that are dynamically generated at runtime. We cannot see it at runtime because it does not produce any visible output. It only used as a “Container” of other web server controls.
Ans: The Repeater control contains the templates, such as HeaderTemplate, ItemTemplate, SeparatorTemplate, AlternatingItemTemplate, FooterTemplate etc. To see an example, Read More from here.
Ans: The @Page directive is responsible to assign page specific attributes for the page parser and the compiler in an ASP.NET Application. Following is the simple example of @Page directive; which is the first line of your .aspx web page.
Ans: Following are all the common built-in objects in ASP.NET that we can use frequently during website development.
- Session etc
Ans: An index is a physical structure that contains pointers that point to a physical location of the data. It is possible to create an index on one or more columns of a table, and each index is given a name.
An index is an ordered list of the contents of a columns or a group of columns of a table, in that “ROWID” indicates exactly where the record is stored in the table.
The users can see the index name but cannot see the indices themselves; they are just used to speed up queries. An Index can give you improves query performance because a “seek action” (it means you can able to locate records without having to examine every row to locate those records) occurs for retrieving records from your table in a query. There are several key features of creating an index, few of them are:
– Indices are created in an existing table to locate rows more quickly and efficiently
– It is used to speed up queries
– It is used to improve query performance of a database application
Ans: A cursor is a database object used by applications in the procedural logic to manipulate data in a row-by-row basis instead of the typical SQL commands that operate on all or parts of rows as sets of data. Following are the steps to create cursor:
– Declare a cursor
– Open a cursor
– Fetch a row from the cursor
– Perform your task on fetched row
– Close a cursor
– Deallocate the cursor
Ans: It is appropriate to use nested Master Pages in an ASP.NET Website when we deal with several hierarchical levels in a Website. For an example, if we are creating “œSchool Management System” so there should be several hierarchies of departments such as Student, Teacher, and Admin etc; In this case we can use nested master pages.
Ans: Usually the Web.config file contains configuration settings for a web application. The appSettings section contains set of user-defined values for the whole web application. Following is the simple example that specifies the “ConnectionString” and “Email” that we can use later throughout the project.
<add key="ConnectionString" value="myConnectionString here.." />
<add key="Email" value="[email protected]"/>
Ans: A Web form belongs to the System.Web.UI.Page Class from .NET Framework Class Library.
Ans: Integer, String, Currency, Double, and Date.
Ans: The EnableViewState property enables the “ViewState” property on the page. When the EnableViewState property is set to false (means Off), the page does not store the users input during post back requests of the webpage. On other hand, when this property is set to true (means On), the page saves the users input between post back requests of the webpage. Following is the simple example that states that the EnableViewState property is set to “Off”.
Inherits="Default" EnableViewState="true" %>
Ans: The SiteMapPath Control helps to display all the web pages into hierarchical path including the root which helps users to navigate the web pages of the website. Therefore, it is known as the breadcrumb or eyebrow navigation control. To see an example, Read More from here.
Ans: Sometimes it becomes necessary to work with multiple tables as though they were a single entity or object. When we want to show result set from one or more related tables at one place, JOINS are comes into the picture. Following are the types of SQL JOINS that we can use in our day to day development:
- 1. INNER JOIN: It also known as “Equi Join” because the WHERE statement generally compares two columns from two tables with the “= (that is a equivalence operator)”, most commonly used type, many database systems use this as by default join. INNER JOIN returns all the rows from both the tables where there is a match. In short, we can say that use it when you are want to select only those rows that have values in common in the columns specified in the “ON” clause, which is required. Following is the simple example of INNER JOIN which perform join ON “studid” which can be match rows and common between both the tables:
Example:SELECT s.studid, s.studname, r.marks FROM Student s INNER JOIN Result r
ON r.studid = s.studid;
- 2. LEFT JOIN: It returns all the rows from the LEFT table, even if there is no match in the RIGHT table. Following is the simple example statement of LEFT JOIN:
Example:SELECT s.studid, s.studname, r.marks FROM Student s LEFT JOIN Result r
ON r.studid = s.studid;
Note: It’ll return all the rows from the left table (Student), even if there is no match in the right table (Result).
- 3. RIGHT JOIN: It returns all the rows from the RIGHT table, even if there is no match in the LEFT table. Following is the simple example statement of RIGHT JOIN:
Example:SELECT s.studid, s.studname FROM Student s RIGHT JOIN Result r
ON r.studid = s.studid;
Note: It’ll return all the rows from the right table (Result), even if there is no match in the left table (Student).
- 4. CROSS JOIN: It returns all the possible combinations of the result set from the listed tables. This kind of join is usually not preferred as it may take a long time to retrieve data and produce huge result set which may decrease the performance of the application.
Example:SELECT * FROM Student CROSS JOIN Department;
Note: It’ll return all the row combination between both the tables. If Student table have “3” records and Department table have “5” records, then it’ll produce total of “15” records, however it doesn’t matter about a row match.
- 5. SELF JOIN: A SELF JOIN is a join of a table with itself. A common use of this join is when the table stores entities or records which have a hierarchical relationship between them. For example, if you want to show name of the employee and corresponding manager as a pair, student and corresponding faculty as a pair etc.
Example:SELECT s1.studname, s2.factname FROM Student s1 INNER JOIN Student s2
ON s1.studid = s2.factid;
Note: It’ll return the names of student and corresponding faculty as a pair.
Ans: The Web Server controls are server-side controls so all the validations are performed at the server-side; whereas the HTML controls are client-side controls so all the validations are performed at the client-side. Web browser does not understand server controls so after page processing all the server controls are converted into html controls to display results on the browser.
Ans: The Code-behind feature of ASP.NET enables you to divide an ASP.NET page into two files – one consisting of the presentation data (which contains the user interface elements, such as HTML and Web Server Controls), and the second one consisting of the business logic (which contains the event-handling process to handle the events that are fired by the controls). It also allows us to debug and trace the code.
The file that contains the presentation data has the “.aspx” extension, for example myFile.aspx; whereas the file contains the business logic has the “.cs” or “.vb” extension depending upon the type of selected programming language that is C# or VB respectively, for example “myFile.aspx.cs” or “myFile.aspx.vb”.
Ans: The Label control represents HTML tag; whereas the Literal control represents plain text (when it converted, rendered and becomes ready to show data on the web browser) which is not surrounded by any HTML tag.
Ans: There are two types of Cookies available in ASP.NET.
- Session Cookie: This type of Cookie resides on the client machine for a single session until the user does not Logout.
- Persistent Cookie: This type of Cookie resides on a user’s machine for a period specified for it to expire, such as 1 day, 7 day, 1 month etc.
Ans: The Session.Abandon() method kills the user session explicitly. You can also use Session.Remove(“mySession”) method to remove any specific one session OR Session.RemoveAll() method to remove all the sessions.
Ans: Following are the common properties that can be use for any validation control.
Ans: The CrossPagePostBack is used to access previous page controls to next page using PostBackUrl property of web server control in Asp.net. To see an example, Read More from here.
Ans: Yes, we can validate ASP.NET DropDownList by using RequiredFieldValidator. To perform this validation, we have to set the InitialValue property of RequiredFieldValidator control, like this.
<asp:ListItem Text="Please select" Value="0" Selected="True"></asp:ListItem>
<asp:ListItem Text="Asp.net" Value="1"></asp:ListItem>
<asp:ListItem Text="C#" Value="2"></asp:ListItem>
<asp:RequiredFieldValidator ID="rfvmyDropDown" runat="server" ControlToValidate="myDropDown"
ErrorMessage="*" InitialValue="0" />
Ans: Following are the common ASP.NET Web form events available:
- Page_Error etc.
Ans: The Namespaces are the way to organize programming code. It eliminates the chances of name conflicts or duplication. For example, myProject.Default1, myproject.Webform1, where myProject is a namespace and Default1, and Webform1 are the class respectively.
You can use namespaces outside your project by referring them using “References” dialog box by right clicking on project and include in code file using “Imports” in .vb and “using” in .cs statement to access members of the namespaces in code. Most likely we can use it when we use “3-tire” or “n-tire” architecture with business logic (BAL), data access logic (DAL) and so on.
Ans: A static variable is a same as constant variable but we can change the value of static variable and we can access the variables without creating class objects or instances.
Ans: We can implement Interface when we want that the “derived” class must implement all the methods of a “base” class; whereas on the other hand we can use Abstract Class when we want only some method of “base” class in our “derived” class.
Ans: The System Exception is thrown by “Common Language Runtime” (CLR); whereas the Application Exception is thrown by same “Application” or “Website”.
Ans: Following are the some common differences between a class and a structure:
– It is a reference type
– It can have destructor
– All variables in classes are by default private
– Good to be used from architecture view as it provides high flexibility
– Null value can be assigned to a variable in a class
– It is a value type
– It cannot have destructor
– All variables in structure are public
– Good to be used for simple data structures
– Null value assignment is not feasible in a structure
Ans: Following are the some common differences between a Response.Redirect and a Server.Transfer:
– It is used to redirect a user to another webpage or website permanently
– It causes additional roundtrips to the server on each request
– It is used to navigate within the same website as well as from one website to another website
– Since it has round-trips, it provides less response as compared to Response.Transfer method
– It is used only to transfer .aspx pages but not website
– It preserves server resources and avoids the unnecessary roundtrips to the server
– It is only used to navigate within the same website and not outside website
– Since it has no round-trips, it provides faster response and does not update the client’s browser url history
Note: The round-trip is a process of a webpage from client to the server and then back from server to the client, including client request to server response.
Ans: A HAVING clause used to specify a search condition for a “GROUP BY” or an Aggregate functions, such as AVG, SUM etc; whereas a WHERE clause is applied to filter out each rows from the table.
The main difference between both of them is that a HAVING clause can be used only with the SELECT statement; whereas a WHERE clause can also be used with DELETE and UPDATE commands.
Ans: A Table-Valued Parameters (TVP) is introduced in SQL Server 2008. The Table-Valued Parameters are declared using “User-Defined Table Type”; it is used to send multiple rows of data to a stored procedure or a function without creating a temporary table or passing in multiple parameters. To see an example, Read More from here.
Ans: A Constructors are special methods, used when instantiating a class. It can never return anything, which is why you don’t have to define a return type for it. To see an example, Read More from here.
Destructors method called once an object is disposed, and can be used to cleanup resources used by the object. Destructors don’t look very much like other methods. To see an example, Read More from here.
Ans: The Session object encapsulates the state of the client and the web browser.