Tuesday, November 20, 2012

What is Query String? What are its advantages and limitations?

Tags

The Query String helps in sending the page information to the server.

The Query String has the following advantages:
  • Every browser works with Query Strings.
  • It does not require server resources and so does not exert any kind of burden on the server.

The following are the limitations of Query String:
  • Information must be within the limit because URL does not support many characters.
  • Information is clearly visible to the user, which leads to security threats.

What is IIS? Why is it used?

Tags
Internet Information Services (IIS) is created by Microsoft to provide Internet-based services to ASP.NET Web applications. It makes your computer to work as a Web server and provides the functionality to develop and deploy Web applications on the server. IIS handles the request and response cycle on the Web server. It also offers the services of SMTP and FrontPage server extensions. The SMTP is used to send emails and use FrontPage server extensions to get the dynamic features of IIS, such as form handler.

What is the behavior of a Web browser when it receives an invalid element?

Tags
The behavior of a Web browser when it receives an invalid element depends on the browser that you use to browse your application. Most of the browsers ignore the invalid element; whereas, some of them display the invalid elements on the page.

What are the advantages of the code-behind feature?

Tags

The code-behind feature of ASP.NET offers a number of advantages:
  • Makes code easy to understand and debug by separating application logic from HTML tags
  • Provides the isolation of effort between graphic designers and software engineers
  • Removes the problems of browser incompatibility by providing code files to exist on the Web server and supporting Web pages to be compiled on demand.

What is the difference between Custom Control and User Control?

Tags
Custom Controls are compiled code (Dlls), easier to use, difficult to create, and can be placed in toolbox. Drag and Drop controls. Attributes can be set visually at design time. Can be used by Multiple Applications (If Shared Dlls), Even if Private can copy to bin directory of web application add reference and use. Normally designed to provide common functionality independent of consuming Application. 
User Controls are similar to those of ASP include files, easy to create, can not be placed in the toolbox and dragged - dropped from it. A User Control is shared among the single application files.

What are the difference between Structure and Class?

Tags

  • Structures are value type and Classes are reference type
  • Structures can not have constructor or destructors.
  • Classes can have both constructor and destructors.
  • Structures do not support Inheritance, while Classes support Inheritance.

What is the difference between static or dynamic assemblies?

Tags
Assemblies can be static or dynamic. 

Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files. 

Dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.

What’s a bubbled event?

Tags
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their event handlers, allowing the main DataGrid event handler to take care of its constituents.

What is the difference between Server.Transfer and response.Redirect?

Tags
The Server.Transfer () method stops the current page from executing, and runs the content on the specified page, when the execution is complete the control is passed back to the calling page. 
While the Response.Redirect () method transfers the control on the specified page and the control is never passed back to calling page after execution.

What is the difference between Classic ASP and ASP.Net?

Tags

    ASP is Interpreted language based on scripting languages like Jscript or VBScript.
  • ASP has Mixed HTML and coding logic.
  • Limited development and debugging tools available.
  • Limited OOPS support.
  • Limited session and application state management.
  • ASP.Net is supported by compiler and has compiled language support.
  • Separate code and design logic possible.
  • Variety of compilers and tools available including the Visual studio.Net.
  • Completely Object Oriented.
  • Complete session and application state management.
  • Full XML Support for easy data exchange.

What are basic methods of a DataAdapter?

Tags

These are the most commonly used methods of a DataAdapter:
  • Fill
  • Executes the Select command to fill the DataSet object with data from the data source. It an also be used to update (refresh) an existing table in a DataSet with changes made to the data in the original data source if there is a primary key in the table in the DataSet.
  • FillSchema
  • Uses the SelectCommand to extract just the schema for a table from the data source, and creates an empty table in the DataSet object with all the corresponding constraints.
  • Update
  • Calls the respective InsertCommandUpdateCommand, or DeleteCommand for each inserted, updated, or deleted row in the DataSet so as to update the original data source with the changes made to the content of the DataSet. This is a little like the UpdateBatch method provided by the ADO Recordset object, but in theDataSet, it can be used to update more than one table.

What is the use of Command objects?

Tags

They are used to connect a Connection object to a DataReader or DataSet. Following are the methods provided by aCommand object:
  • ExecuteNonQuery
  • Executes the command defined in the CommandText property against the connection defined in theConnection property for a query that does not return any row (an UPDATE, DELETE, or INSERT). Returns an Integer indicating the number of rows affected by the query.
  • ExecuteReader
  • Executes the command defined in the CommandText property against the connection defined in theConnection property. Returns a "reader" object that is connected to the resulting row set within the database, allowing the rows to be retrieved.
  • ExecuteScalar
  • Executes the command defined in the CommandText property against the connection defined in theConnection property. Returns only a single value (effectively the first column of the first row of the resulting row set, any other returned columns and rows are discarded). It is fast and efficient when only a "singleton" value is required.

What is the namespace in which .NET has the data functionality class?

Tags

Following are the namespaces provided by .NET for data management:

System.Data

This contains the basic objects used for accessing and storing relational data, such as DataSetDataTable, andDataRelation. Each of these is independent of the type of data source and the way we connect to it.

System.Data.OleDB

It contains the objects that we use to connect to a data source via an OLE-DB provider, such as OleDbConnection,OleDbCommand, etc. These objects inherit from the common base classes, and so have the same properties, methods, and events as the SqlClient equivalents.

System.Data.SqlClient

This contains the objects that we use to connect to a data source via the Tabular Data Stream (TDS) interface of Microsoft SQL Server (only). This can generally provide better performance as it removes some of the intermediate layers required by an OLE-DB connection.

System.XML

This contains the basic objects required to create, read, store, write, and manipulate XML documents according to W3C recommendations.

What is the difference between a struct and a class in C#?

Tags
 From language spec: The list of similarities between classes and structs is as follows. Longstructs can implement interfaces and can have the same kinds of members as classes. Structs differ from classes in several important ways; however, structs are value types rather than reference types, and inheritance is not supported for structs. Struct values are stored on the stack or in-line. Careful programmers can sometimes enhance performance through judicious use of structs. For example, the use of a struct rather than a class for a Point can make a large difference in the number of memory allocations performed at runtime. The program below creates and initializes an array of 100 points. With Point implemented as a class, 101 separate objects are instantiated-one for the array and one each for the 100 elements.

Is there a way of specifying which block or loop to break out of when working with nested loops?

Tags
 The easiest way is to use goto:
using System;
class BreakExample
{
 public static void Main(String[] args) {
  for(int i=0; i<3; i++)
  {
   Console.WriteLine("Pass {0}: ", i);
   for( int j=0 ; j<100 ; j++ )
   {
    if ( j == 10)
     goto done;
    Console.WriteLine("{0} ", j);
   }
   Console.WriteLine("This will not print");
  }
  done:
   Console.WriteLine("Loops complete.");
 }
}

Is there any sample C# code for simple threading?

Tags

using System;
using System.Threading;
class ThreadTest
{
 public void runme()
 {
  Console.WriteLine("Runme Called");
 }
 public static void Main(String[] args)
 {
  ThreadTest b = new ThreadTest();
  Thread t = new Thread(new ThreadStart(b.runme));
  t.Start();
 }
}

My switch statement works differently than in C++! Why?

Tags
C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#:
switch(x)
{
 case 0: // do something
 case 1: // do something as continuation of case 0
 default: // do something in common with
  //0, 1 and everything else
 break;
}
To achieve the same effect in C#, the code must be modified as shown below (notice how the control flows are explicit):
class Test
{
 public static void Main() {
  int x = 3;
  switch(x)
  {
   case 0: // do something
   goto case 1;
   case 1: // do something in common with 0
   goto default;
   default: // do something in common with 0, 1, and anything else
   break;
  }
 }
}

What is implementation and interface inheritance?

Tags

When a class (type) is derived from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance.
When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance.
In general Classes can be derived from another class, hence support Implementation inheritance. At the same time Classes can also be derived from one or more interfaces. Hence they support Interface inheritance.

Monday, November 19, 2012

What is the lifespan for items stored in ViewState?

Tags
The items stored in ViewState live until the lifetime of the current page expires including the postbacks to the same page.

How can we identify that the Page is Post Back?

Tags
Page object has an "IsPostBack" property, which can be checked to know that is the page posted back.

In which event are the controls fully loaded?

Tags
Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event

What is the basic difference between ASP and ASP.NET?

Tags
The basic difference between ASP and ASP.NET is that ASP is interpreted; whereas, ASP.NET is compiled. This implies that since ASP uses VBScript; therefore, when an ASP page is executed, it is interpreted. On the other hand, ASP.NET uses .NET languages, such as C# and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL).

What is ASP.NET?

Tags
ASP.NET is a specification developed by Microsoft to create dynamic Web applications, Web sites, and Web services. It is a part of .NET Framework. You can create ASP.NET applications in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages, such as VBScript. The Web Forms support to create powerful forms-based Web pages. You can use ASP.NET Web server controls to create interactive Web applications. With the help of Web server controls, you can easily create a Web application.

What is ASP?

Tags
Active Server Pages (ASP), also known as Classic ASP, is a Microsoft's server-side technology, which helps in creating dynamic and user-friendly Web pages. It uses different scripting languages to create dynamic Web pages, which can be run on any type of browser. The Web pages are built by using either VBScript or JavaScript and these Web pages have access to the same services as Windows application, including ADO (ActiveX Data Objects) for database access, SMTP (Simple Mail Transfer Protocol) for e-mail, and the entire COM (Component Object Model) structure used in the Windows environment. ASP is implemented through a dynamic-link library (asp.dll) that is called by the IIS server when a Web page is requested from the server.