ASP.Net Interview Questions and Answers

In this blog, I have collected few ASP.Net interview questions and answers.


Q. HTTP Handler vs HTTP Module in ASP.Net

HTTP handler is a process which runs against an HTTP request. Based on file extension HTTP handler executes. Custom HTTP handler can be created on specific requirement.

Generic Web handler (.ashx) - Default HTTP handler for all web handlers. It has no UI.

HTTP Modules-  It is involved in the life cycle of a request. In a request, there could be various stages like Security, Exception Logging etc.

Q. What is IsPostBack

IsPostBack is to check whether the page is rendered for the first time or being loaded in response to postback. It returns boolean value i.e. true or false.

Q. What is view state in ASP.Net

View state is used to maintain the state on a page when an HTTP request made.

Q. Response.Redirect vs Server.Transfer

Response.Redirect - It makes a round trip and next URL is visible in the browser.
Server.Transer - It does not make round trip and current URL only is visible in the browser. So no change in URL. Server.Transfer takes 2 parameters, first is URL and another is preserved form which is a boolean value. By default 2nd parameter is true.


System.Collections.Specialized.NameValueCollection prevForm = Request.Form;
string val = prevForm["txtName"];

Q. Cross Page Posting.

Cross page posting allows posting from one page to another page.
We can check cross page postback by using
To do this we need to set postback URL property of a button.

Page.IsCrossPagePostBack

Q. What is Global.asax file

It is an ASP.Net application file. The code is written in Global.asax file works at the Application level for eg - Application_Start, Application_End, Session_Start, Session_End

Q. How to access MasterPage control in child control


MasterPage.cs file:

 public string UserName
    {
        get
        {
            return (String)Session["Name"];
        }
        set
        {
            Session["Name"] = value;
        }
    }

Child ASPX Page -

  <%@ MasterType VirtualPath ="~/Site.master" %>

Child ASPX.CS Page -

Master.UserName = "My User Name";

Q. Authentication vs Authorization

Authentication is the process of verifying user identity.
Authorization is the process of identifying what access a user has.
Authentication occurs before Authorization.

Q. ExecuteScalar vs ExecuteNonQuery vs ExecuteReader


ExecuteNonQuery - Execute SQL statement and returns the number of rows affected.

ExecuteScalar - It will return single value

ExecuteReader - It will return set of rows. This is read-only and forward-only.

Q. SQLDataReader

It is a forward-only way to read data from SQL.
Read(), NextResult() are few method from SQLDataReader.

Note: In ADO we have record set but in ADO.Net we have DataSet

Q. Two fundamentals object in ADO.Net

DataReader and DataSet

DataSet is a disconnected architecture, DataReader is a connected architecture.
DataSet contains more than one table.

Q. Methods of SQLDataAdapter

Fill() - Get table structure with data.
Update() -
FillSchema() - It creates just a blank table same as sql table structure

Q. Joins in SQL

Inner Join - Get the rows where there is a match in both the tables.

Left Outer Join - Get the rows from the first of left side table.

Right Outer join - Get the rows from the first of right side table.

Full Outer Join - Get all the rows in both the tables.

Cross join - Result is equal to the number of rows in first table times the number of rows in the second table.

Self Join - Join a single table to itself, in this case, you are using the same table twice.

Union vs Union All - Union gets distinct value only. Union All allows duplicate values.


SQL Constraints - It is used to specify the rule for data in a table.
Following constraints are available in SQL- NOT NULL, UNIQUE, PRIMARY, FOREIGN KEY etc.

Q. Primary Key vs Foreign Key vs Unique Key

A table can have multiple unique and foreign keys. However, a table can have only one primary key.

Unique key columns are allowed to hold NULL values. A Unique key can accept only one null value.
A Foreign key can hold NULL values.

Q. Delete vs Truncate

Truncate Delete
1.Reset table to empty state. It is a DDL command.
2.Where clause can not be used with truncate command.
3. Faster than Delete
4. Rollback is not possible.
1.It is a DML command.
2. Where clause can be used with Delete command.
3. Slower than truncate.
4. Rollback is possible.

Q. View state vs Session

View state is applicable on a web page only, a session is a global variable and applicable through out the site.
View state can be stored in client side only. A session can be stored on the server also.
ViewState is stored in a hidden control.

Q. Cast vs Convert in SQL

Cast can not be used for formatting purpose.
Cast can not convert a DateTime to a specific format.
Syntax - cast(@var,as date)

Convert is used to fomat data. Eg convert(varchar,datetime, 103)
convert(data_type,expression, style)

Q. Clustered and Non Clustered Index

Index is a object in database which can be created on or more than one columns
Indexing will read column and reform data in a relevant structure to minimize
the comparison which helps in searching a record.

Cluster index - It arranges tables in a physical order. Due to this reason, a table can have only one clustered index.

To check cluster index on a table

Execute sp_helpindex tablename

By default, a clustered index is applicable on a table on the primary key.
But we can change cluster index key.
To do this we need to delete the existing cluster index and write below query.

create clustered Index CLS_IDX_tble1_firstname_city on table1 (firstname desc, city asc)

It will create a clustered index on table1 for first name and city column. As it is applicable on more than one column, so it is called composite cluster index.
So, a table can have only one clustered index.

Non-clustered index - A table can have more than one non-clustered index. It uses row address to find the record.
A nonclustered index can be understood with index given in a text book.
A clustered index is faster than nonclustered index.

create NonClustered Index NIDX_tble1 on table1(firstname)

Q. Is it possible to use any other sign instead of $ in jquery


yes

Normally we write code as below:

  <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 $(document).ready(function () {
            alert("hi");


        });

OR

 jQuery(document).ready(function () {
            alert("hi");


        });

To use any other character instead of $ we can write below code.

    <script type="text/javascript">
        var $y = jQuery.noConflict(); // or  var $y = $.noConflict();
        $y(document).ready(function () {
            alert("hi");

        });        

    </script>





Comments

Popular