Thursday, December 24, 2009

How to update an xml file with XmlDocument

Used Classes
XmlDocument
XmlNodeList

Before running the code our xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category ID="01">
<MainCategory>XML</MainCategory>
<Description>This is a list my XML articles.</Description>
<Active>true</Active>
</Category>
</CategoryList>

After running the code our xml becomes this:

<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category ID="01">
<MainCategory>ASP.NET</MainCategory>
<Description>This is now my ASP.NET list.</Description>
<Active>false</Active>
</Category>
</CategoryList>

The code which does that looks like this:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" Debug="true" %>

<script runat="server">
void Page_Load(object sender, System.EventArgs e){
if(!Page.IsPostBack){
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("categories.xml"));

XmlNodeList nodeList = xmlDoc.SelectNodes("/CategoryList/Category[@ID='01']");

// update MainCategory
nodeList[0].ChildNodes[0].InnerText = "ASP.NET";
// update Description
nodeList[0].ChildNodes[1].InnerText = "This is now my ASP.NET list.";
// update Active
nodeList[0].ChildNodes[2].InnerText = "false";

// Don't forget to save the file
xmlDoc.Save(Server.MapPath("categories.xml"));
Response.Write("XML File updated!");
}
}

</script>

Monday, November 16, 2009

String Format for DateTime [C#]

This example shows how to format DateTime using String.Format method. All formatting can be done also using DateTime.ToString method.

Custom DateTime Formatting
There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed), t (P.M or A.M) and z (time zone).

Following examples demonstrate how are the format specifiers rewritten to the output.

[C#]
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);

String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone

You can use also date separator / (slash) and time sepatator : (colon). These characters will be rewritten to characters defined in the current DateTimeForma­tInfo.DateSepa­rator and DateTimeForma­tInfo.TimeSepa­rator.

[C#]
// date separator in german culture is "." (so "/" changes to ".")
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9/3/2008 16:05:07" - english (en-US)
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9.3.2008 16:05:07" - german (de-DE)

Here are some examples of custom date and time formatting:

[C#]
// month/day numbers without/with leading zeroes
String.Format("{0:M/d/yyyy}", dt); // "3/9/2008"
String.Format("{0:MM/dd/yyyy}", dt); // "03/09/2008"

// day/month names
String.Format("{0:ddd, MMM d, yyyy}", dt); // "Sun, Mar 9, 2008"
String.Format("{0:dddd, MMMM d, yyyy}", dt); // "Sunday, March 9, 2008"

// two/four digit year
String.Format("{0:MM/dd/yy}", dt); // "03/09/08"
String.Format("{0:MM/dd/yyyy}", dt); // "03/09/2008"

Standard DateTime Formatting
In DateTimeForma­tInfo there are defined standard patterns for the current culture. For example property ShortTimePattern is string that contains value h:mm tt for en-US culture and value HH:mm for de-DE culture.

Following table shows patterns defined in DateTimeForma­tInfo and their values for en-US culture. First column contains format specifiers for the String.Format method.

Specifier DateTimeFormatInfo property Pattern value (for en-US culture)
t ShortTimePattern h:mm tt
d ShortDatePattern M/d/yyyy
T LongTimePattern h:mm:ss tt
D LongDatePattern dddd, MMMM dd, yyyy
f (combination of D and t) dddd, MMMM dd, yyyy h:mm tt
F FullDateTimePattern dddd, MMMM dd, yyyy h:mm:ss tt
g (combination of d and t) M/d/yyyy h:mm tt
G (combination of d and T) M/d/yyyy h:mm:ss tt
m, M MonthDayPattern MMMM dd
y, Y YearMonthPattern MMMM, yyyy
r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (*)
s SortableDateTi­mePattern yyyy'-'MM'-'dd'T'HH':'mm':'ss (*)
u UniversalSorta­bleDateTimePat­tern yyyy'-'MM'-'dd HH':'mm':'ss'Z' (*)
(*) = culture independent

Following examples show usage of standard format specifiers in String.Format method and the resulting output.

[C#]
String.Format("{0:t}", dt); // "4:05 PM" ShortTime
String.Format("{0:d}", dt); // "3/9/2008" ShortDate
String.Format("{0:T}", dt); // "4:05:07 PM" LongTime
String.Format("{0:D}", dt); // "Sunday, March 09, 2008" LongDate
String.Format("{0:f}", dt); // "Sunday, March 09, 2008 4:05 PM" LongDate+ShortTime
String.Format("{0:F}", dt); // "Sunday, March 09, 2008 4:05:07 PM" FullDateTime
String.Format("{0:g}", dt); // "3/9/2008 4:05 PM" ShortDate+ShortTime
String.Format("{0:G}", dt); // "3/9/2008 4:05:07 PM" ShortDate+LongTime
String.Format("{0:m}", dt); // "March 09" MonthDay
String.Format("{0:y}", dt); // "March, 2008" YearMonth
String.Format("{0:r}", dt); // "Sun, 09 Mar 2008 16:05:07 GMT" RFC1123
String.Format("{0:s}", dt); // "2008-03-09T16:05:07" SortableDateTime
String.Format("{0:u}", dt); // "2008-03-09 16:05:07Z" UniversalSortableDateTime


Thursday, September 24, 2009

Reading CheckBoxes and Radio Buttons


Input tags with the type attribute checkbox can be grouped like radio buttons
so that several checkboxes have the same name. However, any number of checkboxes
can be selected by the user. Working with checkboxes in JavaScript is similar
to but not exactly the same as working with radio buttons. Here is a short example
that demonstrates getting values from checkboxes and radio buttons in the same
form:

MUSIC SURVEY





GETTING ALL THE VALUES

A series of checkboxes with the same name are reflected as an array of checkbox
objects. In this example each check box input tag is named Music
but has a different value. Since there are identically named input tags of the
same type, an array of checkbox objects named Music is created.
When the button in this form is pressed, it passes a reference to the form to
a function named, in this case, showBoxes(frm). The function loops
through the checkbox array within the form. To access the check box array from
the form reference it is only necessary to append the name of the checkboxes
to the form reference:
frm.Music
For example to access the number of elements in the array:
frm.Music.length
or if the variable i contains the index of one of the elements,
here is how you would check to see if that element had been checked:
if (frm.Music[i].checked)
or get that element's value:
frm.Music[i].value
Since many values may be checked, this example gathers the values from each by appending each value
on to the end of a string. Since the string is eventually displayed in an alert dialog each value is
separated by a "\n", or new line character. In this case the string is named messagemessage = message + frm.Music[i].value + "\n"

Here is the complete page:
<HTML>
<HEAD>
<TITLE>JavaScript - Reading Checkboxes and Radio Buttons</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showBoxes(frm){
var message = "Your chose:\n\n"

//For each checkbox see if it has been checked, record the value.
for (i = 0; i < frm.Music.length; i++)
if (frm.Music[i].checked){
message = message + frm.Music[i].value + "\n"
}

//For each radio button if it is checked get the value and break.
for (var i = 0; i < frm.Performer.length; i++){
if (frm.Performer[i].checked){
message = message + "\n" + frm.Performer[i].value
break
}
}
alert(message)
}

//NOTE THE onClick="" empty event handlers in the checkbox and radio input fields below
//are there to fix a bug in Netscape 2.0X. Placing an onClick handler in imput fields fixes
//a bug where input objects inside tables are reflected more than once.

//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#ffffff">
<FORM NAME="boxes">
<HR size=1 noshade>
<h2>Music Survey </h2>
<TABLE BORDER="1" CellSpacing="0" CellPadding="6">
<TR>
<TD align="right">I enjoy:</TD>
<TD><INPUT TYPE="Checkbox" NAME="Music" VALUE="Classical" onClick="" CHECKED>Classical</TD>
<TD><INPUT TYPE="Checkbox" NAME="Music" VALUE="Chamber" onClick="">Chamber</TD>
<TD><INPUT TYPE="Checkbox" NAME="Music" VALUE="Jazz" onClick="" CHECKED>Jazz</TD>
<TD><INPUT TYPE="Checkbox" NAME="Music" VALUE="Rock" onClick="">Rock</TD>
<TD><INPUT TYPE="Checkbox" NAME="Music" VALUE="Punk" onClick="">Punk</TD>
</TR>
<TR>
<TD><div align="right">Favourite Performer:</div></TD>
<TD><INPUT TYPE="radio" NAME="Performer" VALUE="Aitken" onClick="">Aitken</TD>
<TD><INPUT TYPE="radio" NAME="Performer" VALUE="Coltrane" onClick="" CHECKED>Coltrane</TD>
<TD><INPUT TYPE="radio" NAME="Performer" VALUE="Julliard" onClick="">Julliard</TD>
<TD><INPUT TYPE="radio" NAME="Performer" VALUE="Kronos" onClick="">Kronos</TD>
<TD><INPUT TYPE="radio" NAME="Performer" VALUE="Waits" onClick="">Waits</TD>
</TR>
</TABLE>
<P>
<INPUT TYPE="Button" VALUE="Tell Us What You Like!" onClick="showBoxes(this.form)">
</P>
</FORM>
</BODY>
</HTML>


ASP NET AJAX Coding for Refresh Date Time without Refresh

Introduction AJAX
AJAX stands for Asynchronous JavaScript And XML.
AJAX is a new technique to develop a interative web page and responsible to exchange data with the behind server without reload the web page.
AJAX increase the speed and usability of the web application.
AJAX is based on JavaScript and XMLHttpRequest.

ASP.NET AJAX combines the power of ASP.NET on the server with the richness of client-side AJAX execution. Asp.net AJAX is a free framework for quickly develop a more interative and usability web page that work almost across all browsers - IE, Firefox and etc.
To download asp.net ajax library click here
Sample asp.net ajax below show you a simple coding for asp.net ajax to refresh date time without reload the page

Result - After compile the code, Both date time is same.

Result - After user click the refresh button, is only update the date time in <asp:update panel>

.aspx - asp net Front Page
<body>
<form id="form1" runat="server">
Outside of update panel <br />
<asp:Label ID="noAjaxtimetxt" Text="" runat="server"></asp:Label>
<br /><br />
<table bgcolor="yellow"><tr><td>

Inside update panel
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:Label ID="Ajaxtimetxt" Text="" runat="server" />
<asp:Button ID="btn" Text="refresh" runat="server" />

</ContentTemplate>
</asp:UpdatePanel>

</td></tr></table>
</form>
</body>

.vb - asp net Code Behind Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
noAjaxtimetxt.Text = Date.Now()
Ajaxtimetxt.Text = Date.Now()
End Sub

META http-equiv Auto Refresh every 10 second

Meta Object
It represents an HTML element.
It is a element provides meta-information about a HTML document (descriptions and keywords for search engines and refresh rates).

Meta Object have 4 properties:
content - set or get a value (any text)
httpEquiv - Connect to http header (content-type, expires,refresh,set-cookie)
name - name of attribute (author,description,keywords,generator,etc)
scheme - format for the attribute value

Example below show you the using of http-equiv,content and name
Below example will show automatic refresh the page every 10 seconds.
Http-equiv="refresh" will do the refresh action and content=10 is telling
http-equiv to do the refresf after every 10 seconds.

If you need to test it, you just copy and paste to ur file and run it.

<head>
<meta http-equiv="refresh" content="10" />
<meta content='programmingschools,Javascript, asp net programming,' name='keywords' /> </head>
<script type="text/javascript">
now = new Date();
hour = now.getHours();
min = now.getMinutes();
sec = now.getSeconds();
document.write(hour + ":" + min + ":" + sec );
</script>
<body>
</body>

Tuesday, September 15, 2009

Adding Meta Tags to the Head in ASP.NET 2.0

// Render:
HtmlMeta meta = new HtmlMeta();
meta.Name = "keywords";
meta.Content = "Some words listed here";
this.Header.Controls.Add(meta);

// Render:
meta = new HtmlMeta();
meta.Name = "robots";
meta.Content = "noindex";
this.Header.Controls.Add(meta);

// Render:
meta = new HtmlMeta();
meta.Name = "date";
meta.Content = DateTime.Now.ToString("yyyy-MM-dd");

meta.Scheme = "YYYY-MM-DD";

Sunday, May 31, 2009

.NET – Short interview Questions

Introduction
This article contains the short answer interview questions related to .NET, Mostly these questions are asked in the interviews so take a look of these, I am sure it will definitely help you.

Questions
Q1. Explain the differences between Server-side and Client-side code?
Ans. Server side code will execute at server end (where the website is hosted) and all the business logic will execute at server end where as Client side code will execute at client side (usually written in javascript, vbscript, jscript) at browser end.

Q2. What type of code (server or client) is found in a Code-Behind class?
Ans. Server side code.

Q3. How to make sure that value is entered in an asp:Textbox control?
Ans. Use a RequiredFieldValidator control.

Q4. Which property of a validation control is used to associate it with a server control on that page?
Ans. ControlToValidate property.

Q5. How would you implement inheritance using VB.NET & C#?
Ans. C# Derived Class : Baseclass
VB.NEt : Derived Class Inherits Baseclass

Q6. Which method is invoked on the DataAdapter control to load the generated dataset with data?
Ans. Fill() method.

Q7. What method is used to explicitly kill a user’s session?
Ans. Session.Abandon()

Q8. What property within the asp:gridview control is changed to bind columns manually?
Ans. Autogenerated columns is set to false

Q9. Which method is used to redirect the user to another page without performing a round trip to the client?
Ans. Server.Transfer method.

Q10. How do we use different versions of private assemblies in same application without re-build?
Ans.Inside the Assemblyinfo.cs or Assemblyinfo.vb file, we need to specify assembly version.
assembly: AssemblyVersion

Q11. Is it possible to debug java-script in .NET IDE? If yes, how?
Ans. Yes, simply write “debugger” statement at the point where the breakpoint needs to be set within the javascript code and also enable javascript debugging in the browser property settings.

Q12. How many ways can we maintain the state of a page?
Ans. 1. Client Side – Query string, hidden variables, viewstate, cookies
2. Server side – application , cache, context, session, database

Q13. What is the use of a multicast delegate?
Ans. A multicast delegate may be used to call more than one method.

Q14. What is the use of a private constructor?
Ans. A private constructor may be used to prevent the creation of an instance for a class.

Q15. What is the use of Singleton pattern?
Ans. A Singleton pattern .is used to make sure that only one instance of a class exists.

Q16. When do we use a DOM parser and when do we use a SAX parser?
Ans. The DOM Approach is useful for small documents in which the program needs to process a large portion of the document whereas the SAX approach is useful for large documents in which the program only needs to process a small portion of the document.

Q17. Will the finally block be executed if an exception has not occurred?
Ans.Yes it will execute.

Q18. What is a Dataset?
Ans. A dataset is an in memory database kindof object that can hold database information in a disconnected environment.

Q19. Is XML a case-sensitive markup language?
Ans. Yes.

Q20. What is an .ashx file?
Ans. It is a web handler file that produces output to be consumed by an xml consumer client (rather than a browser).

Q21. What is encapsulation?
Ans. Encapsulation is the process of hiding all of the details of an object that do not contribute to its essential characteristics.

Q22. What is Overloading?
Ans. Overloading enables method to be defined with the same name but with different parameters. In other words it allows you to have multiple implementations of a method.

Q23. What is Overriding?
Ans. Overriding is the capability of a class to override the characteristic of the parent class.

Q24. What is a Delegate?
Ans. A delegate is a strongly typed function pointer object that encapsulates a reference to a method, and so the function that needs to be invoked may be called at runtime.

Q25. Is String a Reference Type or Value Type in .NET?
Ans. String is a Reference Type object.

Q26. What is a Satellite Assembly?
Ans. Satellite assemblies contain resource files corresponding to a locale (Culture + Language) and these assemblies are used in deploying an application globally for different languages.

Q27. What are the different types of assemblies and what is their use?
Ans. Private, Public(also called shared) and Satellite Assemblies.

Q28. Are MSIL and CIL the same thing?
Ans. Yes, CIL is the new name for MSIL.

Q29. What is the base class of all web forms?
Ans. System.Web.UI.Page

Q30. How to add a client side event to a server control?
Ans. Example… BtnSubmit.Attributes.Add(”onclick”,”javascript:fnSomeFunctionInJavascript()”);

Q31. How to register a client side script from code-behind?
Ans. Use the Page.RegisterClientScriptBlock method in the server side code to register the script that may be built using a StringBuilder.

Q32. Can a single .NET DLL contain multiple classes?
Ans. Yes, a single .NET DLL may contain any number of classes within it.

Q33. What is DLL Hell?
Ans. DLL Hell is the name given to the problem of old unmanaged DLL’s due to which there was a possibility of version conflict among the DLLs.

Q34. can we put a break statement in a finally block?
Ans. The finally block cannot have the break, continue, return and goto statements.

Q35. What is a CompositeControl in .NET?
Ans. CompositeControl is an abstract class in .NET that is inherited by those web controls that contain child controls within them.

Q36. Which control in asp.net is used to display data from an xml file and then displayed using XSLT?
Ans. Use the asp:Xml control and set its DocumentSource property for associating an xml file, and set its TransformSource property to set the xml control’s xsl file for the XSLT transformation.

Q37. Can we run ASP.NET 1.1 application and ASP.NET 2.0 application on the same computer?
Ans. Yes, though changes in the IIS in the properties for the site have to be made during deployment of each.

Q38. What are the new features in .NET 2.0?
Ans. Plenty of new controls, Generics, anonymous methods, partial classes, iterators, property visibility (separate visibility for get and set) and static classes.

Q39. Can we pop a MessageBox in a web application?
Ans. Yes, though this is done clientside using an alert, prompt or confirm or by opening a new web page that looks like a messagebox.

Q40. What is managed data?
Ans. The data for which the memory management is taken care by .Net runtime’s garbage collector, and this includes tasks for allocation de-allocation.

Q41. How to instruct the garbage collector to collect unreferenced data?
Ans. We may call the garbage collector to collect unreferenced data by executing the System.GC.Collect() method.

Q42. How can we set the Focus on a control in ASP.NET?
Ans. txtBox123.Focus(); OR Page.SetFocus(NameOfControl);

Q43. What are Partial Classes in Asp.Net 2.0?
Ans. In .NET 2.0, a class definition may be split into multiple physical files but partial classes do not make any difference to the compiler as during compile time, the compiler groups all the partial classes and treats them as a single class.

Q44. How to set the default button on a Web Form?

Ans.

Q45.Can we force the garbage collector to run?
Ans. Yes, using the System.GC.Collect(), the garbage collector is forced to run in case required to do so.

Q46. What is Boxing and Unboxing?
Ans. Boxing is the process where any value type can be implicitly converted to a reference type object while Unboxing is the opposite of boxing process where the reference type is converted to a value type.

Q47. What is Code Access security? What is CAS in .NET?
Ans. CAS is the feature of the .NET security model that determines whether an application or a piece of code is permitted to run and decide the resources it can use while running.

Q48. What is Multi-tasking?
Ans. It is a feature of operating systems through which multiple programs may run on the operating system at the same time, just like a scenario where a Notepad, a Calculator and the Control Panel are open at the same time.

Q49. What is Multi-threading?
Ans. When an application performs different tasks at the same time, the application is said to exhibit multithreading as several threads of a process are running.2

Q50. What is a Thread?
Ans. A thread is an activity started by a process and its the basic unit to which an operating system allocates processor resources.

Q51. What does AddressOf in VB.NET operator do?
Ans. The AddressOf operator is used in VB.NET to create a delegate object to a method in order to point to it.

Q52. How to refer to the current thread of a method in .NET?
Ans. In order to refer to the current thread in .NET, the Thread.CurrentThread method can be used. It is a public static property.

Q53. How to pause the execution of a thread in .NET?
Ans. The thread execution can be paused by invoking the Thread.Sleep(IntegerValue) method where IntegerValue is an integer that determines the milliseconds time frame for which the thread in context has to sleep.

Q54. How can we force a thread to sleep for an infinite period?
Ans. Call the Thread.Interupt() method.

Q55. What is Suspend and Resume in .NET Threading?
Ans. Just like a song may be paused and played using a music player, a thread may be paused using Thread.Suspend method and may be started again using the Thread.Resume method. Note that sleep method immediately forces the thread to sleep whereas the suspend method waits for the thread to be in a persistable position before pausing its activity.

Q56. How can we prevent a deadlock in .Net threading?
Ans. Using methods like Monitoring, Interlocked classes, Wait handles, Event raising from between threads, using the ThreadState property.

Q57. What is Ajax?
Ans. Asyncronous Javascript and XML – Ajax is a combination of client side technologies that sets up asynchronous communication between the user interface and the web server so that partial page rendering occur instead of complete page postbacks.

Q58. What is XmlHttpRequest in Ajax?
Ans. It is an object in Javascript that allows the browser to communicate to a web server asynchronously without making a postback.

Q59. What are the different modes of storing an ASP.NET session?
Ans. InProc (the session state is stored in the memory space of the Aspnet_wp.exe process but the session information is lost when IIS reboots), StateServer (the Session state is serialized and stored in a separate process call Viewstate is an object in .NET that automatically persists control setting values across the multiple requests for the same page and it is internally maintained as a hidden field on the web page though its hashed for security reasons.

Q60. What is a delegate in .NET?
Ans. A delegate in .NET is a class that can have a reference to a method, and this class has a signature that can refer only those methods that have a signature which complies with the class.

Q61. Is a delegate a type-safe functions pointer?
Ans. Yes

Q62. What is the return type of an event in .NET?
Ans. There is No return type of an event in .NET.

Q63. Is it possible to specify an access specifier to an event in .NET?
Ans. Yes, though they are public by default.

Q64. Is it possible to create a shared event in .NET?
Ans. Yes, but shared events may only be raised by shared methods.

Q65. How to prevent overriding of a class in .NET?
Ans. Use the keyword NotOverridable in VB.NET and sealed in C#.

Q66. How to prevent inheritance of a class in .NET?
Ans. Use the keyword NotInheritable in VB.NET and sealed in C#.

Q67. What is the purpose of the MustInherit keyword in VB.NET?
Ans. MustInherit keyword in VB.NET is used to create an abstract class.

Q68. What is the access modifier of a member function of in an Interface created in .NET?
Ans. It is always public, we cant use any other modifier other than the public modifier for the member functions of an Interface.

Q69. What does the virtual keyword in C# mean?
Ans. The virtual keyword signifies that the method and property may be overridden.

Q70. How to create a new unique ID for a control?
Ans. ControlName.ID = “ControlName” + Guid.NewGuid().ToString(); //Make use of the Guid class

Q71. What is a HashTable in .NET?
Ans. A Hashtable is an object that implements the IDictionary interface, and can be used to store key value pairs. The key may be used as the index to access the values for that index.

Q71. What is an ArrayList in .NET?
Ans. Arraylist object is used to store a list of values in the form of a list, such that the size of the arraylist can be increased and decreased dynamically, and moreover, it may hold items of different types. Items in an arraylist may be accessed using an index.

Q72. What is the value of the first item in an Enum? 0 or 1?
Ans. 0

Q73. Can we achieve operator overloading in VB.NET?
Ans. Yes, it is supported in the .NET 2.0 version, the “operator” keyword is used.

Q74. What is the use of Finalize method in .NET?
Ans. .NET Garbage collector performs all the clean up activity of the managed objects, and so the finalize method is usually used to free up the unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc.

Q75. How do you save all the data in a dataset in .NET?
Ans. Use the AcceptChanges method which commits all the changes made to the dataset since last time Acceptchanges was performed.

Q76. Is there a way to suppress the finalize process inside the garbage collector forcibly in .NET?
Ans. Use the GC.SuppressFinalize() method.

Q77. What is the use of the dispose() method in .NET?
Ans. The Dispose method in .NET belongs to IDisposable interface and it is best used to release unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc from the memory. Its performance is better than the finalize() method.

Q78. Is it possible to have have different access modifiers on the get and set methods of a property in .NET?
Ans. No we can not have different modifiers of a common property, which means that if the access modifier of a property’s get method is protected, and it must be protected for the set method as well.

Q79. In .NET, is it possible for two catch blocks to be executed in one go?
Ans. This is NOT possible because once the correct catch block is executed then the code flow goes to the finally block.

Q80. Is there any difference between System.String and System.StringBuilder classes?
Ans. System.String is immutable by nature whereas System.StringBuilder can have a mutable string in which plenty of processes may be performed.

Q81. What technique is used to figure out that the page request is a postback?
Ans. The IsPostBack property of the page object may be used to check whether the page request is a postback or not. IsPostBack property is of the type Boolean.

Q82. Which event of the ASP.NET page life cycle completely loads all the controls on the web page?
Ans. The Page_load event of the ASP.NET page life cycle assures that all controls are completely loaded. Even though the controls are also accessible in Page_Init event but here, the viewstate is incomplete.

Q83. How is ViewState information persisted across postbacks in an ASP.NET webpage?
Ans. Using HTML Hidden Fields, ASP.NET creates a hidden field with an ID=”__VIEWSTATE” and the value of the page’s viewstate is encoded (hashed) for security.

Q84. What is the ValidationSummary control in ASP.NET used for?
Ans. The ValidationSummary control in ASP.NET displays summary of all the current validation errors.

Q85. What is AutoPostBack feature in ASP.NET?
Ans. In case it is required for a server side control to postback when any of its event is triggered, then the AutoPostBack property of this control is set to true.

Q86. What is the difference between Web.config and Machine.Config in .NET?
Ans. Web.config file is used to make the settings to a web application, whereas Machine.config file is used to make settings to all ASP.NET applications on a server(the server machine.

Q87. What is the difference between a session object and an application object?
Ans. A session object can persist information between HTTP requests for a particular user, whereas an application object can be used globally for all the users.

Q88. Which control has a faster performance, Repeater or Datalist?
Ans. Repeater.

Q89. Which control has a faster performance, Datagrid or Datalist?
Ans. Datalist.

Q90. How to we add customized columns in a Gridview in ASP.NET?
Ans. Make use of the TemplateField column.

Q91. Is it possible to stop the clientside validation of an entire page?
Ans. Set Page.Validate = false;

Q92. Is it possible to disable client side script in validators?
Ans. Yes. simply EnableClientScript = false.

Q93. How do we enable tracing in .NET applications?
Ans. <%@ Page Trace=”true” %>

Q94. How to kill a user session in ASP.NET?
Ans. Use the Session.abandon() method.

Q95. Is it possible to perform forms authentication with cookies disabled on a browser?
Ans. No, it is not possible.

Q96. What are the steps to use a checkbox in a gridview?
Ans.
OnCheckedChanged=”Check_Clicked”>


Q97. What are design patterns in .NET?
Ans. A Design pattern is a repeatitive solution to a repeatitive problem in the design of a software architecture.

Q98. What is difference between dataset and datareader in ADO.NET?
Ans. A DataReader provides a forward-only and read-only access to data, while the DataSet object can carry more than one table and at the same time hold the relationships between the tables. Also note that a DataReader is used in a connected architecture whereas a Dataset is used in a disconnected architecture.

Q99. Can connection strings be stored in web.config?
Ans. Yes, in fact this is the best place to store the connection string information.

Q100. Whats the difference between web.config and app.config?
Ans. Web.config is used for web based asp.net applications whereas app.config is used for windows based applications.