ASP.NET Interview Questions and Answers (1544) - Page 39

In which situations would you use HTML controls in an ASP.NET web site?

These are the situations...

1)If any .html page is used in the ASP.NET Web Site.
Only HTML controls can be used in this case.
2) Designing: Table Control, Horizontal Rule
Table Control: acts as a container for other control.
Horizontal Rule: for drawing horizontal Lines.
3) If State Management is not required in a given page.
4) Javascript code that needs to be executed without posting the page back to the server.example: sum of 2 numbers by clicking an HTML button and displaying the result in an alert.
When a dynamic compilation of a website project is bad ?

Dynamic compilation happens for a website project not for a web application project.

If the site is very large, dynamic compilation of a Web site project might take a noticeable amount of time. Dynamic compilation occurs when a request for a site resource is received after an update to the site, and the request that triggers compilation might be delayed while the required resources are compiled. If the delay is unacceptable, you can pre-compile the site. However, then some of the advantages of dynamic compilation are lost.
What is scavenging ?

When server running your ASP.NET application runs low on memory resources, items
are removed from cache depending on cache item priority. Cache item priority is set when you add item to cache. By setting the cache item priority controls the items scavenging are removed first.
how to caputure user control button click event in aspx page

in ascx page


using System;

using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
public event EventHandler obj;


public string st
{
get
{
return this.TextBox1.Text;
}

}
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
obj(sender, e);
}
}



In aspx page


protected void Page_Load(object sender, EventArgs e)

{
WebUserControl1.obj += new EventHandler(Button1_Click);
}

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = WebUserControl1.st;

}

If Master Page is attached with a child, which event's will be fired first. Explain the execution of page?

• Content page PreInit event.
• Master page controls Init event.
• Content controls Init event.
• Master page Init event.
• Content page Init event.
• Content page Load event.
• Master page Load event.
• Master page controls Load event.
• Content page controls Load event.
• Content page PreRender event.
• Master page PreRender event.
• Master page controls PreRender event.
• Content page controls PreRender event.
• Master page controls Unload event.
• Content page controls Unload event.
• Master page Unload event.
• Content page Unload event
difference between Early Binding and Late Binding?

Early Binding:

Compiler bind the objects to methods at the compile time.This is called early binding or static binding.Function overloading is example for early binding. Early bound objects allow the compiler to allocate memory and perform other optimizations before an application executes. For example, the following code fragment declares a variable to be of type

Example

' Add Imports statements to the top of your file.
Imports System.IO

'...
' Create a variable to hold a new object.
Dim FS As FileStream
' Assign a new object to the variable.
FS = New FileStream("C:\tmp.txt", FileMode.Open)



Late Binding:

Compiler bind the objects to methods at the runtime.This is called late binding or dynamic binding.Function overriding is example for late binding. Objects of this type can hold references to any object, but lack many of the advantages of early-bound objects.
Different between Response.TransmitFile and Response.WriteFile ?

TransmitFile : sends the file to the client without loading it to the Application memory on the server. It is the ideal for if the file size being download is large.

WriteFile : loads the file being download to the server’s memory before sending it to the client. If the file size is large, you might the ASPNET worker process might get restarted.
Is it good to store connection strings in a separate text file for your application ?

NOTE: This is objective type question, Please click question title for correct answer.
Are Web services only written in .NET ?

No.....

A web service is based on SOAP (Simple Object Access Protocol). So any technology which is able to implement SOAP should be able to create a web service. For example we can create web services in .NET or Java.

Thanks and Regards
Akiii
What is the name given to a type of assembly which which contains localized resources?

NOTE: This is objective type question, Please click question title for correct answer.
which is server side state management technical?

NOTE: This is objective type question, Please click question title for correct answer.
How can you assign page specific attributes in an ASP.NET application?

NOTE: This is objective type question, Please click question title for correct answer.
Whats is the difference between API and WebServices?

1) Web Services gives the output in the form of XML or JSON.Where as API return the output in the form of void,scalar or generic type
2)We need to add web references for web-services and add references for API
In MVC Framework, who decides what to render in the VIEW ?

NOTE: This is objective type question, Please click question title for correct answer.
What are Scripting Objects?

NOTE: This is objective type question, Please click question title for correct answer.
What is the need for Hash Table and Serialization in .Net ?

The Hashtable object contains items in key/value pairs. The keys are used as indexes. We can search value by using their corresponding key.
In .NET, the class that implements a hash table is the Hashtable class.

By using Add Method we can add elements to the Hashtable as shown below:

private Hashtable table = new Hashtable();


public void AddEntry(BookEntry entry)
{
table.Add( entry.GetPerson(), entry );
}

Once the Hashtable gets populated,you can search and retrieve data in it by calling the indexer for the Hashtable class as shown below:

public BookEntry GetEntry(Person key)

{
return (BookEntry) table[key];
}

You can also remove the records from the Hashtable by calling the Remove Method which takes a key identifying the element you want to remove as shown below:

public void DeleteEntry(Person key)

{
table.Remove( key );
}

The data populated from the Hashtable can be saved using Serialization process.
Serialization is a process where the object gets converted into a linear sequence of Bytes for storage or transmission to another location.
This process can be done by using BinaryFormater class which serializes Hashtable object to file stream.

public void Save()

{
Stream s = File.Open("Phone.bin", FileMode.Create, FileAccess.ReadWrite);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, table);
s.Close();
}


By using the Deserialize method, you can get back the recovered Hashtable object as shown below:

s = File.Open("Phone.bin", FileMode.Open, FileAccess.Read);

BinaryFormatter b = new BinaryFormatter();
table = (Hashtable) b.Deserialize(s);

How to manage unhandled Exception?

You can manage unhandled exception by configuring the <customErrors> element in web.config file.
It has 2 attributes:

Mode Attribute:It specifies how the custom error page should be displayed.
It has 3 values:
on - Displays custom error pages at both the local and remote client.
off - Disables custom error pages at both the local and remote client.
RemoteOnly - Displays custom error pages only at the remote client as it displays default asp.net error page for local machine.This is default setting in web.config file.
defaultRedirect:It is an optional attribute to specify the custom error page to be displayedwhen an error occurs.
The custom error page is displayed based on http error statusCode using error element inside the customError element.
If none of the specific statusCode matches with it, it will redirect to defaultRedirect page.

Example:

<customErrors mode="RemoteOnly" defaultRedirect="~/DefaultErrorPage.htm">

<error statusCode="103" redirect="NoAccess.htm"/>
<error statusCode="104" redirect="FileNotFound.htm"/>
</customErrors>

What is the use of Using Statement

Using statement is used similar to finally block that is to dispose the object.
It declares that you are using a disposable object for a short period of time.
Once the using block ends,the CLR releases the corresponding object immediately by calling its dispose() method.

Example:

//Write code to allocate some resource

//List the allocated resource in a comma-separated list inside
//the parenthesis of the using block

using(...)
{
//use the allocated resource
}

//Here dispose() method is called for all the object referenced without writing any additional code.

What is the use of throw statement?

A throw statement is used to generate exception explicitly.
This throw statement is generally used in recording error in event log or sending an Email notification about the error.
Avoid using throw statement as it degrades the speed.

Example:

try

{
//Code that might generate error
}
catch(Exception error)
{
//Code that handle errors occurred in try block

throw; //Re throw of exception to add exception details in event log or sending email
}

//Code that handle errors occurred in try block
}
finally
{
//Code to dispose all allocated resources
}

Format2

try
{
//Code that might generate error
}
finally
{
//Code to dispose all allocated resources
}

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories