Important ASP.Net Interview Questions and Answers

In this blog, I have collected important 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 the 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 a asingle 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 recordset 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. View state vs Session

View state is applicable on a web page only, a session is a global variable and applicable throughout 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 cannot be used for formatting purpose.
Cast cannot 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. 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