May 16, 2011

Differences between user controls and custom controls

This question is asked in every interview happens for asp.net in all organizations, article will help the interviewee (candidate).

 FactorsUser controlCustom control
DeploymentDesigned for single-application scenarios


Deployed in the source form (.ascx) along with the source code of the application


If the same control needs to be used in more than one application, it introduces redundancy and maintenance problems
Designed so that it can be used by more than one application


Deployed either in the application's Bin directory or in the global assembly cache


Distributed easily and without problems associated with redundancy and maintenance
CreationCreation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)Writing involves lots of code because there is no designer support
ContentA much better choice when you need static content within a fixed layout, for example, when you make headers and footersMore suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows
DesignWriting doesn't require much application designing because they are authored at design time and mostly contain static dataWriting from scratch requires a good understanding of the control's life cycle and the order in which events execute, which is normally taken care of in user controls

April 25, 2011

Increase SQL Server performance

Following are tips which will increase your SQl performance :-
  1.  Every index increases the time takes to perform INSERTS, UPDATES and DELETES, so the number of indexes should not be too much. Try to use maximum 4-5 indexes on one table, not more. If you have read-only table, then the number of indexes may be increased.308
  2.  Keep your indexes as narrow as possible. This reduces the size of the index and reduces the number of reads required to read the index.
  3. Try to create indexes on columns that have integer values rather than character values.
  4. If you create a composite (multi-column) index, the order of the columns in the key are very important. Try to order the columns in the key as to enhance selectivity, with the most selective columns to the leftmost of the key.
  5. If you want to join several tables, try to create surrogate integer keys for this purpose and create indexes on their columns.
  6. Create surrogate integer primary key (identity for example) if your table will not have many insert operations.
  7. Clustered indexes are more preferable than nonclustered, if you need to select by a range of values or you need to sort results set with GROUP BY or ORDER BY.
  8. If your application will be performing the same query over and over on the same table, consider creating a covering index on the table.
  9. You can use the SQL Server Profiler Create Trace Wizard with "Identify Scans of Large Tables" trace to determine which tables in your database may need indexes. This trace will show which tables are being scanned by queries instead of using an index.

April 23, 2011

what is Static Constructors?

Static Constructors: A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced.

Static constructors have the following properties:


1. A static constructor does not take access modifiers or have parameters.
2. A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
3. A static constructor cannot be called directly.
4. The user has no control on when the static constructor is executed in the program.
5. A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.

Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.








April 13, 2011

Datatable Pivots with C# and ASP.NET

private DataTable PivotTable(DataTable origTable)
        {
          
                DataTable newTable = new DataTable();
                DataRow dr = null;
                //Add Columns to new Table
                for (int i = 0; i < origTable.Rows.Count; i++)
                    newTable.Columns.Add(origTable.Rows[i][0].ToString(), typeof(String));
                //Execute the Pivot Method
                for (int cols = 0; cols < origTable.Columns.Count; cols++)
                {
                    dr = newTable.NewRow();
                    for (int rows = 0; rows < origTable.Rows.Count; rows++)
                    {
                        if (rows < origTable.Rows.Count)
                        {
                            dr[0] = origTable.Columns[cols].ColumnName; // Add the Column Name in the first Column
                            dr[rows] = origTable.Rows[rows][cols];
                        }
                    }
                    newTable.Rows.Add(dr); //add the DataRow to the new Table rows collection
                }
                newTable.Rows[0].Delete();
                return newTable;
            }
          
        }

April 11, 2011

what is endpoint in wcf

All communication with a Windows Communication Foundation (WCF) service occurs through the endpoints of the service. Endpoints provide clients access to the functionality offered by a WCF service.
Each endpoint consists of four properties:
  • An address that indicates where the endpoint can be found.

  • A binding that specifies how a client can communicate with the endpoint.

  • A contract that identifies the operations available.

  • A set of behaviors that specify local implementation details of the endpoint.

This topic discusses this endpoint structure and explains how it is represented in the WCF object model.

The Structure of an Endpoint

Each endpoint consists of the following:
  • Address: The address uniquely identifies the endpoint and tells potential consumers of the service where it is located. It is represented in the WCF object model by the EndpointAddress class. An EndpointAddress class contains:

    • A Uri property, which represents the address of the service.

    • An Identity property, which represents the security identity of the service and a collection of optional message headers. The optional message headers are used to provide additional and more detailed addressing information to identify or interact with the endpoint.

    For more information, see Specifying an Endpoint Address.

  • Binding: The binding specifies how to communicate with the endpoint. This includes:

    • The transport protocol to use (for example, TCP or HTTP).

    • The encoding to use for the messages (for example, text or binary).

    • The necessary security requirements (for example, SSL or SOAP message security).

    For more information, see Windows Communication Foundation Bindings Overview. A binding is represented in the WCF object model by the abstract base class Binding. For most scenarios, users can use one of the system-provided bindings. For more information, see System-Provided Bindings.

  • Contracts: The contract outlines what functionality the endpoint exposes to the client. A contract specifies:

    • What operations can be called by a client.

    • The form of the message.

    • The type of input parameters or data required to call the operation.

    • What type of processing or response message the client can expect.

    For more information about defining a contract, see Designing Service Contracts.

  • Behaviors: You can use endpoint behaviors to customize the local behavior of the service endpoint. Endpoint behaviors achieve this by participating in the process of building a WCF runtime. An example of an endpoint behavior is the ListenUri property, which allows you to specify a different listening address than the SOAP or Web Services Description Language (WSDL) address. For more information, see ClientViaBehavior.

Go to question list