ASP.net, C# Interview Questions - 1
ASP.net, C# Interview Questions - 1
Below are the Recent interview questions for Asp.Net developers: (as on 07/2011)
A: Implement the “abstract class PageStatePersister” class, with our custom class to serialize data into
binary format. Or override LoadViewstate(), SaveViewState() methods of “Control” class from our
custom server control.
Check: http://msdn.microsoft.com/en-us/library/system.web.ui.pagestatepersister.aspx
A: Yes. extend output caching and to configure one or more custom output-cache providers. storage
options can include local or remote disks, cloud storage, and distributed cache engines. Check:
http://msdn.microsoft.com/en-us/library/ms228124.aspx and
http://www.4guysfromrolla.com/articles/061610-1.aspx
3Q. How to get notified if thread from threadpool completed executing method?
A: In order to be notified when a method is complete, you must supply a callback delegate on the
BeginInvoke(). Delegate type -> new AsyncCallback(CallBack), // callback delegate. check:
http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx
4Q. Write code for reverseChars(whole string), reverseWords & Sort collection (in C#).
// sorts collection
public static string sortwords(string s)
{
List<string> lst = new List<string>();
lst.Add("zz"); lst.Add("ff"); lst.Add("ww"); lst.Add("aa");
lst.Sort();
return String.Join(" ",lst.ToArray());
}
http://rajudasa.blogspot.com
Asp.Net interview questions
A: Code Access Security! Revolves around groups(zones) and permissions. It’s a security model which
determines code is allowed to run or allowed to access a resource etc permissions. Mainly components
from internet, intranet etc zones are checked.
A: Yes, we can using the attributes (ex:[nonserializable]) or mainly with Iserializable interface
implementation with our class (object).
A: Yes, like any other aggregate function, we can call it from sql query. Ex: sql = “Select
mydb.dbo.udFunction(val) As result”. But not like directly stored-procedure call.
A: from content page (.aspx) under “onPreInit” event-handler write this code:
Page.MasterPageFile = “MainMaster.master”;
10Q. What happens if implement Interface first then inherit Class next from your class?
Ex: class Child : I1, BaseA
A: It’s not allowed, since specification (from ECMA standard) says so. And its convention followed by
compilers, that class comes first then interfaces next. Ex: class Child : BaseA, I1,I2
I1 -> show(); & I2 -> show(); // both interfaces contain same method
A: Yes, Its allowed. I1.show() requires explicit implementation in class Child without access-modifier.
Ex: void I1.show(){ .. }
I1.show();
A: Types: Size, Point from System.Drawing namespace are structure types and also Nullable<T> is
too.
13Q. How to call Button1 click event from Button2 click event handler? (Win Form)
http://rajudasa.blogspot.com
Asp.Net interview questions
A: use Abstract classes if you are creating 3rd party component (public & sharable).
Or use Interface for private projects.
A: place the username in application object or D/B then count and check the password attempts.
Forms Authentication – Membership provider by default provides this functionality.
17Q. Assign DataSet to a TextBox, fill it with single value, using one line of coding?
A: ds.Tables[0].Rows[0]["ColumnName"].ToString();
or declaratively:
"Tables[Table1].DefaultView.[0].Name") %>'/>
A: Gridview events:
DataBinding Occurs when the server control binds to a data source. (Inherited from Control.)
DataBound Occurs after the server control binds to a data source. (Inherited from
BaseDataBoundControl.)
(and other common events for sorting, paging, editing, updating, deleting, selecting operations can be
found, check here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx )
http://rajudasa.blogspot.com
Asp.Net interview questions
They can prevent the sql injection attacks. by preserving any sql string formats(but not concat
to coding).
Easy to understand the sqlquery while dynamic sql creation.
21Q. Write a query to add two columns from a table and show a single column result?
22Q. Inner Join or Outer Join requires Foreign-Key between tables to use them?
A: Yes, sum(columnName) used to add the single column values, giving a total value.
24Q. what’s the Inner Join and Left Outer Join output of below tables?
Col1
col1
1
Null
5
1
Null
6
1 1 1 1
Nul Nul
l l
6 Nul
l
25Q. To Add or Update a property to TextBox, what type you use: UserControl or Custom Server
Control?
A: Custom Server Control is used to Alter or creating a control from scratch. It’s a class library project
(DLL).
http://rajudasa.blogspot.com
Asp.Net interview questions
A: Master pages provide common layout. User control used to aggregate controls, both are useful for
reuse and better maintenance.
27Q. How many Clustered & Non-Clustered indexes can be created in a table?
A: 1 Clustered (by default PK column) & 249 for 2005v, 999 for 2008v, Non-Clustered indexes can be
created.
A:
function isInteger(s){
var i; s = s.toString();
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (isNaN(c)) {
alert("Given value is not a number");
return false;
}
}
return true;
}
<input type=text name=en onKeyup="isInteger(this.value)">
30Q. In which event all web controls are initiated/initialized in asp.net?
31Q. How to get gridview or dataset from one page to another page?
A: use the PostbackUrl on Button or Server.Transfer() from code in first page with public property
providing access to that gridview or dataset. From the second page, use the “Page.PreviousPage” to
get the first page and access its public property. (check my blog post for details and code).
32Q. How to filter gridview data based on dropdownlist selected item and by declaratively (not
programmatically) ?
A: Enable the ‘AutoPostback’ on dropdownlist, use the SqlDataSource control with ‘ControlParameter’
point to this dropdownlist and then assign this datasource control to gridview.
A: Yes, it’s a virtual method, also there is an ‘Init’ event which is not.
34Q. Is ‘commit work’ exists? What is the difference with commit transaction?
http://rajudasa.blogspot.com
Asp.Net interview questions
A: FrameworkInitialize() method.
37Q. If Page contains <file upload> control, the <form> should contain the ___ attribute?
A: ENCTYPE=”multipart/form-data”
A: Provide public property in Page, from Usercontrol, use “this.Page”, cast it to specific page type, then
call its public property.
40Q. How to call Page method when Button in User control is clicked?
A: Call public method in Page class from usercontrol of click event after casting the Page to specific
type, or implement the event delegate in usercontrol and allow the container pages to subscribe, so
that user control can call this delegate under button click.
41Q. Difference between ‘Table Variable’ and ‘Temp Table’ in sql server?
A: TV: stored in RAM, No Foreign key support. TT: stored in TempDB d/b, supports Foreign key.
A: Both classes are not derivable. Instances can be created for Sealed class, virtual methods can’t be
created in sealed class. Instances can’t be created for Private constructor class, provide public static
method which will return this instance. Virtual methods can be created in private constructor class. For
further info, Check singleton pattern.
A: Application object: 1.Not threadsafe, use Lock(), UnLock() explicitly. 2. No expiration policy.
Cache Object: 1. Threadsafe (implicit locks). 2. Supports expiration policy (file, time, sql).
http://rajudasa.blogspot.com
Asp.Net interview questions
A: for disposing Unmanaged memory, user may call Dispose() method explicitly, which disposes
memory as need is over. Sometime later GC calls the destructor which handles the release of
unmanaged memory.
A: Typecast Page.Master object to specific masterpage type and use it (or) use "@ MasterType
directive" to access the specific masterpage properties/methods is called strongly typed master pages.
A: “print” works only in sqlserver, where as raisError() can send information to client (.net).
54Q. scenario: custom-class object stored in session and placed in sqlserver. It generates error, (the
culprit, custom class) what might be the reason?
A: The name of an assembly consists of four parts: shortName, culture, version, PublickeyToken. Thus,
two strong named assemblies can have the same PE file name and yet .NET will recognize them as
different assemblies. The public key token is used to make the assembly name unique.
Actually, strong name for an assembly consists of five parts: a public key, a simple name, a
version, an optional culture, and an optional processor architecture.
http://rajudasa.blogspot.com
Asp.Net interview questions
A: Global.asax generates a class called "global". global class derives fron the
System.Web.HttpApplication class.
57Q. How to retrieve specific rows(based on condition) from datatable without dataview?
A: DataRow[] dr = ds.Tables[0].Select("<condition>");
A: “Clone” will copy the structure of a data (Deep copy) where as “Copy” will copy the complete
structure as well as data (shallow copy).
A: using Microsoft® Windows NT… domain controller or Microsoft Windows… Active Directory.
61Q. Default timeout in sqlconnection with sqlserver? and how to extend it?
A: The @import rule allows you to include external style sheets in your document.
64Q. In javascript, what is the output for these: (a)"6"+"5"*2, (b) 5+true, (c) [1, 2, 3].join(",") ?
Besides the above questions, Below are the frequently asked basic
questions:
http://rajudasa.blogspot.com
Asp.Net interview questions
1Q. What is the best way to integrate 3rd party component into your application?
2Q. Write the logic to communicate with different data sources (DBMS) using common classes?
System Test:
http://rajudasa.blogspot.com
Asp.Net interview questions
For Asp.Net developers, these are the topics from which interview
questions will be asked/expected:
http://rajudasa.blogspot.com