You are on page 1of 11

Questions 1. Can multiple catch blocks be executed for a single try statement ? 2.

What is the three services model commonly known as a three-tier application? 3. When would you use Web Services as opposed to a non-serviced .NET component? When would you not use Web services 4. What is the difference between Application_Start and Session_Start functions in ASP.NET applications? 5. What are the modes of session state supported by ASP.NET. Give a brief explanation of each with advantages and disadvantages. 6. What does EnableViewState do ? Why would I want to turn it on or off? 7. What is the difference between Authentication and Authorization ? 8. In ASP.NET what does the following return <% Response.Write(System.Environment.WorkingSet.ToString()) %> 9. What is the difference between web.config and machine.config ? 10. What are the modes of updation in an AJAX UpdatePanel ? What are the triggers of an UpdatePanel ? 11. What is the difference between synchronous and asynchronous web service invocations? What are the advantages and disadvantages of each? 12. Please write a sample program that parses the string into a series of substrings where the delimiter between the substrings is ^*!%~ and then reassembles the strings and delimiters into a single new string where each of the substrings is in the reverse order from the original string. The method must return the final string. For e.g. Original String Token A^*!%~Token B^*!%~Token C^*!%~Token D^*!%~Token E Output String Token E^*!%~Token D^*!%~Token C^*!%~Token B^*!%~Token A

13. Given the following fragment of an ASPX file: <form runat=server method=post id=form1> <asp:TextBox ID=txtName Text=Builder.Com EnableViewState=false/> <br> <asp:TextBox ID=txtName2 Text= EnableViewState=false/> </form> and the following fragments of the ASPX files codebehind file (in C#): protected TextBox txtName = new TextBox(); protected TextBox txtName2 = new TextBox(); // Assume this is properly wired as the Load event handler. private void Page_Load(object source, EventArgs args) { txtName2.Text = txtName.Text; } which of the following is true? a. ASP.NET would generate an exception when it tried to run this. b. Builder.Com would appear in txtName, but an empty string would appear in txtName2. c. Builder.Com would appear in both txtName and txtName2. d. Neither txtName nor txtName2 would render as HTML input controls on the loaded page. e. Builder.Com would appear in txtName, but txtName2 wouldnt render at all i.e., no HTML control with an ID attribute of txtName2 would be present on the loaded page. 14. Can you use User-defined types in Webservices? How will you pass these types or return such types to and from webservice methods? 15. From a book a number of pages are missing. The page numbers of the missing pages are in continuous order for e.g 13,14, The sum of the missing page numbers is 9808. How many and which pages (numbers) are missing ? 16. Write a small program to flip the rows and columns in a DataGrid, i.e. let us say that a table has the following data o Employee ID o Last Name

o o o o o o o o o o o

First Name Title Title of Courtesy Birth Date Hire Date Address City State ZIP Code Salary Marital Status

Using ADO.NET DataSet and DataTable, write a program to read the above table and flip the row and column in the data table and show in a DataGrid DataGrid, 17. Write a program to compute all the permutations of a given string and using MS Office API display how many of the permutations are actual words and how many of them are junk. 18. If you want an ASP.NET function executed on a MouseOver of a button control, where would you add the event handler ? Write a small snippet of code illustrating this. 19. What are the ways to handle concurrency violations in Linq ? Explain with code sample. 20. What are the differences between Windows Communication Foundation (WCF) and Web Services? Answers 1. No. Once the proper catch block is processed, control is transferred to the finally block (if there is one) 2. Presentation (UI), Business Logic(logic and underlying code) and Data (from storage and other sources) 3. Any of the following situations to use Web Services a. Communicating through a firewall b. Application Integration integrating applications written in multiple languages or running on different systems c. B2B integration d. Software reuse Any of the following to NOT use Web Services a. Singe machine applications

b.

Homogenous applications on a LAN

4. Application_Start occurs only once during the lifetime of the application. Session_Start occurs each time the session times out in addition to when the application is restarted. 5. ASP.NET has three modes of session state: a. InProc: Stored the session values in the memory of ASP worker process. Is the fastest, but when worker process is recycled the data is lost b. StateServer: Uses a standalone MS Windows service to store session variables. It can be run on a separate server because it is independent of IIS. Useful for load-balancing situations because multiple servers can share session variables. Session variables arent lost even if the application/IIS is restarted. Performance is slower c. SqlServer: Most useful if persistence of session information is a primary concern. Session data is maintained in SQL Server. Impacts performance. 6. ViewState turns on the automatic state management feature that enables server controls to re-populate their values on a round trip without requiring you to write any code. This feature is not free however, since the state of a control is passed to and from the server in a hidden form field. You should be aware of when ViewState is helping you and when it is not. For example, if you are binding a control to data on every round trip, then you do not need the control to maintain its view state, since you will wipe out any re-populated data in any case. ViewState is enabled for all server controls by default. To disable it, set the EnableViewState property of the control to false. 7. Authentication happens first. You verify users identity based on credentials. Authorization is making sure the user only gets access to the resources he has credentials for. 8. Gives the memory working set. 9. Web.config defines configuration for each application. Machine.config defines the configuration for all ASP.NET applications on a server 10. There are two modes viz. Always and Conditional. Always updates the UpdatePanel controls content on each Postback that starts from anywhere on the web page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls as well as postbacks from controls which are not inside UpdatePanel. Conditional updates the UpdatePanel controls content on the following conditions. a. When a postback trigger is called for that UpdatePanel b. When the UpdatePanels Update method is explicitly called

c. When a parent UpdatePanel is updated. Controls defined inside a <Triggers> node have the capability to update the controls of an UpdatePanel. 11. A synchronous web service call blocks the process until the operation completes. Only then will the next line of execution be invoked. Advantage is ease of implementation and can be used when the service is reliable and guaranteed to return in all cases. Asynchronous web service call does not block the calling process and returns immediately. The client is notified through a callback about the completion of the asynchronous web service. Asynchronous web services are useful if the web service is not fast, or if the client app needs to make concurrent calls to one or more remote services 12. using System; using System.Text; namespace GenericsSample { class Program { static void Main() { string strOriginalString = "Token A^*!%~Token B^*!%~Token C^*!%~Token D^*!%~Token E"; string[] strSeperator = new string[1]; strSeperator[0] = "^*!%~"; string[] strArrayIndividualStrings = strOriginalString.Split(strSeperator, StringSplitOptions.RemoveEmptyEntries); int intLengthOfStringArray = strArrayIndividualStrings.Length; StringBuilder sbOutputString = new StringBuilder(); for (int i = (intLengthOfStringArray - 1); i >= 0; i--) { sbOutputString.Append(strArrayIndividualStrings[i] + strSeperator[0]); } Console.WriteLine("Original String : " + strOriginalString); Console.WriteLine("Output String : " + sbOutputString.ToString()); Console.ReadLine(); } } }

13. Answer is Option d. 14. Yes, you can use User-defined types in Webservices. These types can be passed or returned to and from webservice methods. Custom types that are sent to or from a web service are serialized, enabling them to be passed in XML format. This is referred to as XML Serialization. 15. Let the number of missing pages be n and the first missing page p+1. Then the pages p+1 up to and including p+n are missing, and n times the average of the numbers of the missing pages must be equal to 9808: n? ((p+1)+(p+n))/2 ) = 9808 In other words: n?2?+n+1)/2 = 2????13 So: n?2?+n+1) = 2?????13 One of the two terms n and 2?+n+1 must be even, and the other one must be odd. Moreover, the term n must be smaller than the term 2?+n+1. It follows that there are only two solutions: n=1 and 2?+n+1=2?????13, so n=1 and p=9808, so only page 9808 is missing. n=2???? and 2?+n+1=613, so n=32 and p=290, so the pages 291 up to and including 322 are missing. Because it is asked which pages (plural) are missing, the solution is: the pages 291 up to and including 322 are missing. . 16.
Sub Page_Load(Sender As Object, E As EventArgs) Dim dataArray(,) as string dim i, j as integer

'Create instance of DataSet object dim DS as DataSet = new DataSet() DS.ReadXml(Server.MapPath("Employees.xml")) dim rowCount as integer= DS.Tables(0).Rows.Count dim colCount as integer= DS.Tables(0).Columns.Count redim dataArray(rowCount, colCount) 'save data in a two dimensional array for i = 0 to rowCount -1

for j = 0 to colCount -1 if DS.Tables(0).Rows(i).item(j) is DBNull.value dataArray(i,j)="" else dataArray(i,j) =DS.Tables(0).Rows(i).item(j) end if next next 'Switch columns and rows, dynamically filling in the table dim r as TableRow dim c as TableCell for j = 0 to colCount -1 r = new TableRow() c = new TableCell() c.Controls.Add(new _ LiteralControl(DS.Tables(0).Columns(j).ColumnName)) c.VerticalAlign = VerticalAlign.Top c.Style("background-color") = "lightblue" r.cells.add(c) for i = 0 to rowCount - 1 c = new TableCell() c.Controls.Add(new LiteralControl(dataArray(i,j))) c.VerticalAlign = VerticalAlign.Top r.cells.add(c) next i Table1.Rows.Add(r) next j

End Sub

17. Answer
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; [assembly: CLSCompliant(true)]

namespace Unscramble { class Permutations { private int itemLevel = -1; private int numOfItems; private int permCount; private int[] permutation = new int[0]; private char[] inputCharSet; private List<string> permList = new List<string>(); object missing = System.Reflection.Missing.Value; // Called directly w/o using directive to prevent ambiguity // with System.Windows.Forms.Application object Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); ProgressBar pgProgress = (ProgressBar)Form1 .ActiveForm.Controls["pbProgress"]; public void MakeCharArray(string inputString) { inputCharSet = inputString.ToCharArray(); numOfItems = inputCharSet.Length; Array.Resize(ref permutation, numOfItems); } public void Recursion(int position) { itemLevel++; permutation.SetValue(itemLevel, position); if(itemLevel == numOfItems) { AddPermutation(permutation); } else { for(int currentPosition = 0; currentPosition < numOfItems; currentPosition++) { if(permutation[currentPosition] == 0) { Recursion(currentPosition); }

} } itemLevel--; permutation.SetValue(0, position); } private void AddPermutation(int[] currentPermutation) { string tempPermString = ""; foreach(int item in currentPermutation) { // Build string permutation from position permutation tempPermString += inputCharSet.GetValue(item - 1); } permList.Add(tempPermString); permCount++; } private bool CheckTheSpelling(string theWord) { pgProgress.Increment(1); bool result = false; try { if(wordApp.CheckSpelling(theWord, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing) == true) { result = true; } else { result = false; } } catch(Exception) { wordApp.Quit(ref missing, ref missing, ref missing); } return result; } public string OutputPermutations()

{ //Count all int allPermCount = permList.Count(); var permListTrue = permList.Distinct(); //Count distinct int uniquePermCount = permListTrue.Count(); pgProgress.Maximum = uniquePermCount; permListTrue = permListTrue .Where(perm => CheckTheSpelling(perm) == true) .OrderBy(perm => perm); var permListFalse = permList .Distinct() .Except(permListTrue) .OrderBy(perm => perm); //Count answers int answersFound = permListTrue.Count(); StringBuilder tempDisplay = new StringBuilder(); try { foreach(string permutation in permListTrue) { tempDisplay.AppendLine(permutation + " (true)"); } tempDisplay.AppendLine("-------------------"); foreach(string permutation in permListFalse) { tempDisplay.AppendLine(permutation + " (false)"); } tempDisplay.AppendLine("-------------------"); tempDisplay.AppendLine("Total Permutations: " + allPermCount.ToString()); tempDisplay.AppendLine("Unique Permutations: " + uniquePermCount.ToString()); tempDisplay.AppendLine("Words Found: " + answersFound); } catch(Exception ex) { return ex.ToString(); } finally {

wordApp.Quit(ref missing, ref missing, ref missing); } return tempDisplay.ToString(); } } }

18. In the Attributes Property, Add function. For e.g. btnSubmit.Attributes.Add(onMouseOver, someClientCode();); 19. There are 3 ways provided by LINQ system to handle concurrency conflicts: KeepCurrentValues :- When this option is specified and concurrency conflicts happen LINQ keeps call the LINQ entity object values as it is and does not push the new values from the database in to the LINQ object. OverwriteCurrentValues :- When this option is specified the current LINQ object data is replaced with the database values. KeepChanges :- This is the most weird option but can be helpful in some cases. When we talk about classes it can have many properties. So properties which are changed are kept as it is but the properties which are not changed are fetched from the database and replaced. We need to use the RefereshMode to specify which options we need as shown in the below code snippet. catch (ChangeConflictException ex) { foreach (ObjectChangeConflict objchangeconf in objContext.ChangeConflicts) { objchangeconf.Resolve(RefreshMode.<ModeToBeSelected>); } } Where ModeToBeSelected is one of KeepChanges/KeepCurrentValues/OverwriteCurrentValues 20. Web Services a. Can be accessed only over HTTP b. Works in a stateless environment WCF a. Can be hosted in different types of applications like IIS, WAS, Selfhosting, Managed Windows Services. b. More flexible. If a new version of the service is deployed, you just need to expose a new end.

You might also like