ASP.NET Interview Questions

ASP.NET Interview Questions

1. What is the transport protocol used to call a webservice?Answer: Web Services basically uses Hypertext Transfer Protocol (HTTP) and Simple Object Access Protocol(SOAP) to make business data available on the Web..

2. A button in a webform is class or object? If it is object than which is class for that object? Answer: Webform is a form. We dragdrop button control and create button. We create one button control for any event handling code. Regards,Nand kishore .

3. Explain the life cycle of an ASP .NET page. Answer: Start-properties such as Request,Response,IsPostBack are set.Page IntializationloadValidationPostBack Event handlingRederingUnload.

4. In which interface the template of any control like Gridview would Initiate? Answer: In ItemTemplate Inside TemplateColumn ...

5. How we can set Different levels of Authentication in .Net?What are the difference between Windows Authenticatin, Passport Authentication and Form Authentication? Answer: Windows Authentication Windows Authentication is the default authentication mechanism for ASP.NET applications. Windows Authentication is implemented in ASP.NET using the Windows authentication module. Windows Authentication gets logged ...

6. What is tooltip class? How it was implemented? Answer: ToolTip Class is used to create a custome tooltip message for the any controls and associated with controls.ToolTip objPictureBox=new ToolTip();objPictureBox.Text="This is picturebox control";PictureBox1.Controls.Add(objPictureBox); ...

7. explain virtual function in c# with an example ?Answer: What : Virtual Function is used to have polymorphic Effect in my Architecture.Grammar

8. When using code behind pages, which library must access file import from asp.net environment ?Answer: ASP.Net uses two ways/techniques of coding pages 1) Inline code2) Code behind 1) In Inline code,code is directly embedded directly within asp.net aspx page.2) In code behind technique we have a seprate class that contains our logic for the asp.net .

9. What type of processing model does ASP.NET stimulate? Answer: Event-driven ...

10. What do you mean by Declarative Security and Imperative Security? Explain with an example of usage where you would use them ?Answer: Imperative versus Declarative SecurityThe code security can be implemented by either using the Declarative Security or the Imperative Security. Let us now understand how these two differ.Declarative SecurityThis is accomplished by placing security ...

11. Explain the .NET architecture.

12. How many languages .NET is supporting now? - When .NET was introduced it came with several languages. VB.NET, C#, COBOL and Perl, etc. The site DotNetLanguages.Net says 44 languages are supported.

13. How is .NET able to support multiple languages? - a language should comply with the Common Language Runtime standard to become a .NET language. In .NET, code is compiled to Microsoft Intermediate Language (MSIL for short). This is called as Managed Code. This Managed code is run in .NET environment. So after compilation to this IL the language is not a barrier. A code can call or use a function written in another language.

14. How ASP .NET different from ASP? - Scripting is separated from the HTML, Code is compiled as a DLL, these DLLs can be executed on the server.

15. Resource Files: How to use the resource files, how to know which language to use?

16. What is smart navigation? - The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.

17. What is view state? - The web is stateless. But in ASP.NET, the state of a page is maintained in the in the page itself automatically. How? The values are encrypted and saved in hidden controls. this is done automatically by the ASP.NET. This can be switched off / on for a single control

18. Explain the life cycle of an ASP .NET page.

19. How do you validate the controls in an ASP .NET page? - Using special validation controls that are meant for this. We have Range Validator, Email Validator.

20. Can the validation be done in the server side? Or this can be done only in the Client side? - Client side is done by default. Server side validation is also possible. We can switch off the client side and server side can be done.

21. How to manage pagination in a page? - Using pagination option in DataGrid control. We have to set the number of records for a page, then it takes care of pagination by itself.

22. What is ADO .NET and what is difference between ADO and ADO.NET? -ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate in-memory database where in I can use relationships between the tables and select insert and updates to the database. I can update the actual database as a batch.

23. What’s the difference between Response.Write() andResponse.Output.Write()? Answer:Response.Output.Write() allows you to write formatted output.

24. 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.

25. When during the page processing cycle is ViewState available? Answer:After the Init() and before the Page_Load(), or OnLoad() for a control.

26. What namespace does the Web page belong in the .NET Framework class hierarchy?

System.Web.UI.Page

27. Where do you store the information about the user’s locale? Answers:CodeBehind is relevant to Visual Studio.NET only.

28. What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?Answers:CodeBehind is relevant to Visual Studio.NET only.

29. What is the Global.asax used for? Answers:The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

30. What are the Application_Start and Session_Start subroutines used for? This is where you can set the specific variables for the Application and Session objects.

31. Whats an assembly? Assemblies are the building blocks of the .NET framework;

32. Whats MSIL, and why should my 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.

33. Which method do you invoke on the DataAdapter control to load your generated dataset with data? The Fill() method

34. Can you edit data in the Repeater control? No, it just reads the information from its data source

35. Which template must you provide, in order to display data in a Repeater control? ItemTemplate.

36. Name two properties common in every validation control? ControlToValidate property and Text property.

37. What base class do all Web Forms inherit from? The Page class.

38. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other? Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performas a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address

39. What is ViewState? ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used the retain the state of server-side objects between postabacks.

40. What is the lifespan for items stored in ViewState? Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

41. 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.

42. What are the different types of Session state management options available with ASP.NET?

ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session in memory on the web server. This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server. Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in session are serializable.

43. What is CLR? First of all, VB.NET provides managed code execution that runs under the Common Language Runtime (CLR), resulting in robust, stable and secure applications. All features of the .NET framework are readily available in VB.NET.
The CLR takes care of garbage collection i.e. the CLR releases resources as soon as an object is no more in use. This relieves the developer from thinking of ways to manage memory. CLR does this for them.

44. Which dll handles the request of .aspx page? When the Internet Information Service process (inetinfo.exe) receives an HTTP request, it uses the filename extension of the requested resource to determine which Internet Server Application Programming Interface (ISAPI) program to run to process the request. When the request is for an ASP.NET page (.aspx file), IIS passes the request to the ISAPI DLL capable of handling the request for ASP.NET pages, which is aspnet_isapi.dll.

45. How to create dynamic Gridview? Answers: Many times we have the requirement where we have to create columns dynamically.This article describes you about the dynamic loading of data using the DataTable as the datasource.
Details of the Grid
Let?s have a look at the code to understand better.
Create a gridview in the page,Drag and drop the GridView on to the page
Or

Manually type GridView definition in the page.
public partial class _Default : System.Web.UI.Page
{#region constants
const string NAME = "NAME";
const string ID = "ID";
#endregion
protected void Page_Load(object sender, EventArgs e)

{
loadDynamicGrid();
}
private void loadDynamicGrid()
{
#region Code for preparing the DataTable

DataTable dt = new DataTable();
//Create an ID column for adding to the Datatable
DataColumn dcol = new DataColumn(ID ,typeof(System.Int32));
dcol.AutoIncrement = true;
dt.Columns.Add(dcol);
//Create an ID column for adding to the Datatable
dcol = new DataColumn(NAME, typeof(System.String));
dt.Columns.Add(dcol);
//Now add data for dynamic columns
//As the first column is auto-increment, we do not have to add any thing.
//Let's add some data to the second column.
for (int nIndex = 0; nIndex < 10; nIndex++)
{
//Create a new row
DataRow drow = dt.NewRow();
//Initialize the row data.
drow[NAME] = "Row-" + Convert.ToString((nIndex + 1));
//Add the row to the datatable.
dt.Rows.Add(drow);
}#endregion
//Iterate through the columns of the datatable to set the data bound field dynamically.
foreach (DataColumn col in dt.Columns)
{
//Declare the bound field and allocate memory for the bound field.
BoundField bfield = new BoundField();
//Initalize the DataField value.
bfield.DataField = col.ColumnName;
//Initialize the HeaderText field value.
bfield.HeaderText = col.ColumnName;
//Add the newly created bound field to the GridView.
GrdDynamic.Columns.Add(bfield);
}
//Initialize the DataSource
GrdDynamic.DataSource = dt;

//Bind the datatable with the GridView.
GrdDynamic.DataBind();
}
}

46. How would you get ASP.NET running in Apache web servers - why would you even do this? The mod_mono Apache module is used to run ASP.NET applications within the Apache (http://httpd.apache.org) web server. Mod_mono is available from (http://www.mono-project.com/Downloads).XSP is a standalone web server written in C# that can be used to run your ASP.NET applications. XSP works under both the Mono and Microsoft runtimes and the code is available from(http://www.mono-project.com/Downloads).

47. How to pass text box values to an XML? Answers: //declare an XMLDoc and Attribute<br>dim Attr as XmlAttribute<br>dim doc as XmlDoc<br>doc.load("yourXMLpath")<br>'Create an Element <br>Dim elem As XmlElement = doc.CreateElement("Person")<br>'Create an Attribute<br> Attr = doc.CreateAttribute("Fname")<br>'Assign the value of ur text box <br> Attr.Value = txtFirstName.Text<br> elem.Attributes.SetNamedItem(Attr)<br> Attr = doc.CreateAttribute("Lname")<br> Attr.Value = txtLastName.Text<br> elem.Attributes.SetNamedItem(Attr)<br><br> Dim root As XmlNode = doc.DocumentElement<br> root.AppendChild(elem)<br>'Save the documnet<br> doc.Save("d:Gayathri.xml")<br><br>Sample Output:<br><br><?xml version="1.0" encoding="utf-8"?><br><PassengerDetails><br> <Person Fname="sri" Lname="krishna" /><br> <Person Fname="ram" Lname="krishna" /><br></PassengerDetails>

48. What is IPostBack? How to use it? Answers:

Gets a value indicating whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.
Property Value

true if the page is being loaded in response to a client postback; otherwise, false.

void Page_Load() {
if (!IsPostBack) {
// Validate initially to force asterisks
// to appear before the first roundtrip.
Validate();
}
}

49. How do you create a permanent cookie? Answers: Setting a permanent cookie is similar to Session cookie, except give the cookie an expiration date too. It is very common that you don't specify any arbitrary expiration date, but instead expire the cookie relative to the current date, using the DateAdd() function.
Response.Cookies("Name") = "myCookie"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now()) permanent cookies are available until a specified expiration date and are stored on the hard disk.so set 'expires' property any value greater than DateTime.MinVlue withrespect to the currect datetime.if u want the cookie which never expires set its expires property equal to DateTime.maxValue.

50. Can you explain what inheritance is and an example of when you might use it? Answers: Inheritance helps in the reusability of the code. The class from which another class is derived is called base class. Those methods of the base class can be overridden. The deried class can also implement the methids of the base class. C#.net does not allow multiple inheritance. But multi level inheritance is possible. For eg. Class B derives from Class A, and class C can derive from Class B and so on...
One example in layman terms will be the example of a car. We can define the general features os a car like four tyres, engine poweretc in the base class. The derived class can use this as a base and extend its functionalities like sports car(eg. four wheel drive). Base Class is derived by Sub Class. Bass class type definition and methods are used in sub class object.

public Class Carseeting
Dim seat as int
public function sitting(Byval totalseat as int)as int
seat=totalseat
end function
end class
public class Assemplecar
inherit Carseeting
dim total as int
public function sittingcovercharge(Byval totalseat as int)as int
total+=totalseat*1500
end function
end class
class honda
public sub main()
dim ob as new Assemplecar
c.w.l(ob.sittingcovercharge(ob.sitting(6)))
end sub
end class