Free Shipping Across India | Pay Cash On Delivery | Call: 8970308999 (Mon - Sat)

search lense
Call Us :8970308999Let us call you

asp net interview questions and answers for freshers


This article is giving some of the Asp net interview questions and answers for freshers, this will be helpful for the candidtaes who aresearching for a job in Asp net.

1. What is the main difference between an ASP.NET Web application and a traditional Windows application.

ASP.NET Web applications runs under common language runtime using managed code where as Unmanaged Windows application runs under Windows using unmanaged code.

2. What are the two main parts of the .NET Framework?

The two main parts of the .NET Framework are

  1. The common language runtime (CLR).

  2. The .NET Framework class library.

3. When can’t you use ASP.NET to create a Web application?

When you are developing for non–Microsoft Windows Web servers, such as Linux/Apache.

4. List the four major differences between Web and Windows applications.

Web forms cannot use the standard Windows controls. Instead, they use server controls, HTML controls, user controls, or custom controls created specially for Web forms.

Web applications are displayed in a browser. Windows applications display their own windows and have more control over how those windows are displayed.

Web forms are instantiated on the server, sent to the browser, and destroyed immediately. Windows forms are instantiated, exist for as long as needed, and are destroyed.

Web applications run on a server and are displayed remotely on clients. Windows applications run on the same machine they are displayed on.

5. Describe the life cycle of a Web application: When are Web forms instantiated and how long do they exist?

A Web application starts with the first request for a resource within the application’s boundaries. Web forms are instantiated when they are requested. They are processed by the server and are abandoned immediately after the server sends its response to the client. A Web application ends after all client sessions end.

6. How do you preserve persistent data, such as simple variables, in a Web application?

You can preserve data in state variables, such as ApplicationState, SessionState, or ViewState.

7. How does the .NET Framework organize its classes?

The .NET Framework uses namespaces to organize its classes.

8. In Visual Basic .NET, what is the difference between a class module and a code module?

Class modules are instantiated at run time to create objects that provide separate storage for variables and properties in each instance. Code modules do not have instances, so any module-level variables they use are shared among calls to the module’s procedures.

9. In Visual C#, how do you declare a method to make it available without having to first instantiate an object from the class?

To create a method that can be called without instantiating an object, declare that method as static.

10. How do you call a member of a base class from within a derived class?

To refer to a member of a base class in Visual Basic .NET, use the MyBase keyword. To refer to a member of a base class in Visual C#, use the base keyword.

11. Where would you save the following data items so that they persist between requests to a Web form?

A control created at run time, An object that provides services to all users, User preferences

Save controls created at run time in the Page object’s ViewState.

Save objects that provide services to all users in the Application state.

Save user preferences in SessionState.

12. What is the main difference between the Button server control and the Button HTML control?

When clicked, the Button server control triggers an ASP.NET Click event procedure on the server. The Button HTML control triggers the event procedure indicated in the button’s onclick attribute, which runs on the client.

13. How do you get several RadioButton controls to interoperate on a Web form so that only one of the RadioButton controls can have a value of True/true at any given time?

Set the GroupName property of each RadioButton to the same name.

14. Why does ASP.NET perform validation on both the client and the server?

Client-side validation helps avoid round-trips to the server. Validating on the client ensures that the data is valid before it is submitted, in most cases. However, because validation might be turned off (or maliciously hacked) on the client, data must be revalidated on the server side. This provides full assurance that the data is valid while avoiding as many round-trips as possible.

15. What types of validation would you use to verify that a user entered a valid ­customer number?

You would use a RequiredFieldValidator and a RegularExpressionValidator. If you have access to a list of expected customer numbers, you could replace the RegularExpressionValidator with a CustomValidator that checked the list.

16. What is wrong with the following line of code?


You can’t use the Transfer method with HTML pages. It works only with .aspx pages.

17. Why can’t you open a new browser window from within server code?

Server code executes on the server, whereas the new window is created on the client. You need to use client-side code to do things that affect the client, such as upload files, display new windows, or navigate back in history.

18. What steps would you follow and what objects would you use to quickly find the number of records in a database table?

There are two ways to accomplish this task:

Use a database connection and a command object to execute a SQL command that re-turns the number of rows in the table.

Use a database connection and data adapter object to create a data set for the table, and then get the number rows in the data set.

19. How do typed data sets differ from untyped data sets, and what are the advantages of typed data sets?

Typed data sets use explicit names and data types for their members, whereas untyped data sets use collections to refer to their members. The following examples show a typed reference vs. an untyped reference to a data item:

// Typed reference to the Contacts table's HomePhone column.

DataSet1.Contacts.HomePhoneColumn.Caption = "@Home";

// Untyped reference to the Contacts table's HomePhone column.

DataSet1.Tables["Contacts"].Columns["HomePhone"].Caption = "@Home";

Typed data sets do error checking at design time. This error checking helps catch typos and type mismatch errors, which would be detected only at run time with untyped data sets.

20. How do you call a stored procedure?

Create a command object, set the object’s CommandText property to the name of the stored procedure, and set the CommandType property to StoredProcedure. To execute the stored procedure, use the command object’s ExecuteNonQuery, ExcecuteScalar, ExecuteReader, or ExecutelXmlReader method. For example, the following code calls the Ten Most Expensive Products stored procedure on the Northwind Traders database:

// Create a connection for NorthWind Trader's database.

SqlConnection connNWind = new SqlConnection("integrated security=SSPI;" +

"data source=(local);initial catalog=Northwind");

// Create a command object to execute.

SqlCommand cmdTopTen = new SqlCommand(connNWind);

cmdTopTen.CommandText = "Ten Most Expensive Products";

// Set the command properties.

cmdTopTen.CommandType = CommandType.StoredProcedure;

// Create a data reader object to get the results.

SqlDataReader drdTopTen;

// Open the connection.


// Excecute the stored procedure.

drdTopTen = cmdTopTen.ExecuteReader();

21. Explain the difference between handling transactions at the data set level and at the database level.

Data sets provide implicit transactions, because changes to the data set aren’t made permanent in the database until you call the Update method. To handle transactions in a data set, process the Update method and check for errors. If errors occur during an update, none of the changes from the data set is made in the database. You can try to correct the error and resubmit the update, or you can roll back the changes to the data set using the RejectChanges method.

Databases provide explicit transactions through the Transaction object. You create a Transaction object from a database connection and then assign that Transaction object to the commands you want to include in the transaction through the command object’s Transaction property. As you perform the commands on the database, you check for errors. If errors occur, you can either try to correct them and resubmit the command, or you can restore the state of the database using the Transaction object’s RollBack method. If no errors occur, you can make the changes permanent by calling the transaction object’s Commit method.

22. Explain why exception handling is important to a completed application.

When an unhandled exception occurs in an application, the application stops—the user can’t proceed, and any work he or she did immediately prior to the exception is lost. Exception handling provides a way to intercept and correct unusual occurrences that would otherwise cause these problems.

23. List two different exception-handling approaches in ASP.NET Web applications.

Exceptions can be handled in exception-handling blocks using the Try, Catch, and Finally keywords in Visual Basic .NET or the try, catch, and finally keywords in Visual C#. They can also be handled using Error event procedures at the Global, Application, or Page levels using the Server object’s GetLastError and ClearError methods.

24. Describe the purpose of error pages and why they are needed.

Because Web applications run over the Internet, some exceptions occur outside the scope of the application. This means that your application can’t respond directly to these exceptions. These types of exceptions are identified by HTTP response codes, which IIS can respond to by displaying custom error pages listed in your application’s Web.config file.

25. Explain why tracing helps with exception handling.

Tracing allows you to record unusual events while your application is running, without users being aware of it. If an unanticipated exception occurs, your application can write a message to the trace log, which helps you diagnose problems during testing and after deployment.

26. Write the HTML for a hyperlink that will send mail when the user clicks the link.

&lta href=" from a client&BODY=Some message text."> Send mail

27. Write the code that creates a cookie containing the user name Rob Young and the current date to the user’s computer. Set the cookie to remain on the user’s computer for 30 days.

HttpCookie cookUserInfo = new HttpCookie("UserInfo");

CookUserInfo["Name"] = "Rob Young";

CookUserInfo["Time"] = DateTime.Now.ToString();

cookUserInfo.Expires = DateTime.Now.AddDays(30);


28. What attribute do you use to hide a public .NET class from COM?

Use the ComVisible attribute to select which public .NET classes and members are visible to COM. This attribute applies hierarchically for the assembly, class, and member levels.

29. Why can’t you open a new browser window using server-side code? How would you display a page in a new window with a client-side script?

Server-side code can execute tasks only on the server. To perform a task on the client’s computer, such as opening a new browser window, the code needs to run on the client.

You can open a new window using the DOM window object. For example, the following HTML Button control opens a Help page in a new window:

< button id="butHelp" > Help

29. How do you declare an unmanaged procedure within .NET?

Use the DllImport attribute or a Visual Basic .NET Declare statement to declare an unmanaged procedure for use with a .NET assembly. The DllImport attribute is found in the System.Runtime.InteropServices namespace.

30. Which ASP.NET authentication mode is best suited to identifying and authorizing users who belong to a corporate network?

Windows authentication is best suited to authenticating users of a corporate network because it uses the accounts and permissions that already exist for network users.

31. What is the difference between Windows and Forms authentication user lists in Web.config?

User lists for Windows authentication are included in the &ltauthorization> element of Web.config. User lists for Forms authentications are included in the &ltcredentials> element of Web.config or as part of an external users database or file.

32. How do you require authentication using the Web.config file?

Include the following &ltauthorization> element to require authentication:

33. How do you run a Web application using the permission set of an authenticated user?

Use the identity element in Web.config to execute code using the authenticated user’s account. For example:

34. How does the Secure Sockets Layer (SSL) provide security in a Web application?

SSL protects data exchanged between a client and a Web application by encrypting the data before it is sent across the Internet.

35. How do you begin and end secure communication via SSL?

To begin secure communication, specify https in an address. For example:

To end secure communication, specify http. For example:

36. What permissions do Web applications run under by default?

By default, Web applications run as the ASPNET user, which has limited permissions equivalent to the Users group.

37. Why is the Machine.config file important to deployed Web applications?

The Machine.config file controls many aspects of how Web applications run, including how processes are recycled, what types of request queue limits are imposed, and what interval is used when checking if users are still connected.

38. How do you configure a setup project to install an application over the Web?

To configure a setup project to install an application over the Web, select the Web Bootstrapper option from the setup project’s properties. This setting allows the Windows Installer to be downloaded and installed over the Web.

39. How do you distribute shared components as part of an installation program?

Shared components should be included as a merge module within the setup project. Merge modules manage the installation of shared components so that they’re not unnecessarily overwritten and so that they can be safely removed when no longer used. Unlike regular setup projects, merge modules can’t be installed by themselves—they can be installed only as part of an application installation.

40. How does deploying to a Web farm or a Web garden affect Session state in a Web application?

Web applications that are deployed to a Web farm or a Web garden need to identify a Session state provider in their Web.config file. This is because a single client’s requests can be directed to different processes over the course of his or her session. The Session state provider allows each different process to access the client’s Session state.

41. How do unit, integration, and regression testing relate to each other?

Unit testing is the foundation that ensures that each piece of code works correctly. Integration testing extends this concept by verifying that pieces work together without errors. Regression tests are made up of the existing unit and integration tests, which are run on a regular schedule to assure that new code did not break previously working code.

42. Why is load testing likely to be more important for a Web application than for a stand-alone Windows application?

Because Web applications can be public on the Internet, they can have hundreds, thousands, or even millions of users. Load tests let you simulate the expected demand to locate resource conflicts, performance bottlenecks, and other problems that aren’t apparent in single-user tests.

43. What is the difference between the Debug and Trace classes?

Under the default environment settings, code using the Debug class is stripped out of release builds, while code using the Trace class is left in. The classes are otherwise equivalent.

44. What are the two special steps you need to take to ensure that a COM component can use a component from a .NET assembly?

To use a .NET component from a COM tool, such as VBScript, you must:

Register the .NET assembly in the system registry using RegAsm.exe.

Make sure that the COM component can find the .NET assembly, either by placing the .NET assembly in the global assembly cache, by placing the two components in the same folder, or by following the other assembly-probing rules.

45. When do you generally create a web user control?

You generally create a web user control when you want to create a group of controls that can be reused throughout a project to perform some logical unit of work.

46. When do you generally create a custom control ?

You generally create a custom control when you want to combine one or more existing controls into a compiled assembly that can be easily reused in many different projects.

47. How is deriving important to creating custom Web controls?

Both composite and rendered custom controls are derived from the WebControl base class. That class provides the methods that you override to create the appearance of the custom control.

48. What is the most important method to override when you’re creating a composite custom control?

You override the CreateChildControls method to add existing controls to a composite custom control.

49. How is raising a post-back event in a composite control different from raising a post-back event in a rendered control?

In a composite control, you can use one of the contained controls to raise a post-back event. In a rendered control, you must implement the IPostBackEventHandler interface and write a client-side script to raise a post-back event.

50. Write a directive to cache responses for a Web form for 30 seconds, storing different cache responses based on the value of the lstNames control.

<%@ OutputCache Duration=”30” VaryByParam=”lstNames” %>

A Web form uses fragment caching to store a frequently used user control. At run time, an Object not found error occurs whenever the page is refreshed. What is a likely cause of the error?

The most likely cause is that the user control is referenced in code after it has been cached. Once cached, a user control’s properties and methods are no longer available.

51. How can you detect when application data is about to be removed from the cache?

Use the onRemoveCallback delegate.

52. What is the advantage of using CSS rather than in-line styles for formatting a Web application?

Using CSS allows you to maintain formatting separately from the content of your Web forms, so changes are easier to make and consistency is easier to maintain.

53. Why would you create a style for a class rather than for an HTML element?

You create style classes when you want to apply the same formatting to different types of elements within an application. For example, you might want to create an emphasis style class that applies the same formatting to any text, control, heading, or image that you want to draw the user’s attention to.

54. How do CSS and XSL relate to each other when it comes to formatting a Web application?

CSS and XSL are complementary techniques for formatting. CSS determines the font, color, size, background, and other appearance aspects of HTML elements on a Web page. XSL is used to transform XML files into HTML output. In this way, XSL controls the position and appearance of items based on their content. Used together, XSL performs the high-level tasks of composition and layout while CSS performs the low-level tasks of applying fonts, colors, and other appearance features

55. What are the differences between HTML and XML?

1. HTML uses predefined element names, such as &ltp> and &ltbr&gt. In XML, you create your own element names to identify hierarchical nodes of data.

2. XML syntax is much stricter than HTML: elements must always have end-tags, element names are case sensitive, attribute values must always be enclosed in quotation marks, and nested elements must be terminated within their parent elements.

3. XML identifies data conceptually based on the data’s content, rather than based on the type of formatting to apply.

56. Which HTML attribute does the server control’s ToolTip property map to in the HTML rendered by ASP.NET?

The ToolTip property is rendered as the title attribute at run time.

57. What is the difference between the CurrentCulture property and the Current­UICulture property?

The CurrentCulture property affects how the .NET Framework handles dates, currencies, sorting, and formatting issues. The CurrentUICulture property determines which satellite assembly is used when loading resources.

58. How do you detect the user’s culture?

Use the Request object’s UserLanguages array. The value at element 0 corresponds to one of the culture codes used by the CultureInfo class. For example: SLang = Request.UserLanguages(0)

SLang = Request.UserLanguages(0)

59. What is a neutral culture?

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

Related Tags: Asp net interview questions and answers for freshers, Asp net interview questions, Asp net, Asp net interview questions for freshers.