Tuesday, 28 May 2013

ASP.NET Page Life Cycle Events

ASP.NET Page Life Cycle Events

 The page life cycle events are :

                    

PreInit 


Init


InitComplete

PreLoad


Load


ControlEvents


LoadComplete

PreRender


PreRenderComplete


SaveStateComplete


RenderComplete

Unload



PreInit  : 

This is the initial stage of the page means this is entry point  of page life cycle .
This  checks for is PostBack that means  first time the request is sent or the first time page is processed. Dynamic controls are created in this event such as:
To Set master page dynamically.
To Set the Theme property dynamically,
To Read or set profile property values.


Init:
In this Init Event for the individual control is initialised first  and later the init for the page takes place. This  event is used to initialize the control properties i.e. Each control in the control collection is initialized.

InitComplete:
 View State is turned on in this event . Any changes made to the View State in this event are persisted even after the next postback. In simple sense page is initialised  and  process completes. 

PreLoad:
This event is called before the loading of the page is completed.


Load:
This Load means that all the controls have been loaded completely .  This implies that the  control properties and the view state can be accessed at this point/cycle.
This works like initially ,   the Page Object calls the OnLoad method on the Page object itself  and  then OnLoad method of the control is called .  This means that the Load event of Page occurs before Load event of the controls . 

ControlEvents:
This event manages the events for the buttons , textboxes etc  Like button click event , textbox : textchange event .
In the case of postback , the Page.Isvalid property checks  if the page contains validator controls . 

LoadComplete :
This means that the page has been loaded in the memory. It also marks the beginning of the rendering stage and occurs after the event handling stage. This event is used for tasks such as loading all other controls on the page.

PreRender:
If you need to make any final changes /modification  to the contents of the controls or the page, then we use this event. In this event the PreRender event of the page is called first and later for the child control.

    For eg : To set  the DataSourceId Property  and calling the DataBind method.

PreRenderComplete:
This event is raised after each control's PreRender property/phase  is completed.

SaveStateComplete:
In this event, the current state of the control is completely saved to the ViewState.This is raised after the control state and view state have been saved for the page and for all controls.


RenderComplete:
     The page object calls this method on each control which is present on the page.   This method writes the control’s markup to send it to the browser. 

Unload:
This event is typically used for closing files and database

 connections. 

Friday, 24 May 2013

CONCEPT OF OOPS (Object-Oriented Programming )

CONCEPT OF OOPS -OBJECT ORIENTED PROGRAMMING  

What is Abstraction,Encapsulation,Inheritance,Polymorphism?

  •   ABSTRACTION: Abstraction means to show only the necessary details and hiding non essential features. Abstraction is done when we need to inherit from certain class but do not instantiate the objects of that class. 
  •   ENCAPSULATION  : Encapsulation is wrapping/binding up of data and member functions  in single unit. 
In simple, abstraction is hiding the implementation and encapsulation is to hide data.
  •   INHERITANCE   : Inheritance  enables you to create new classes   that reuse ,extend  and modify the behaviour that is defined in other classes.  In simple terms when one class inherit the  properties , methods etc. of the other class is known as inheritance.  The class whose members are inherited are called base class and other class is known as derived class . 
      for eg : using system ;
                    public class baseclass{
                   public class baseclass( ) 
                   { console.writeline("this is base class constructor");}
                   public void  hello( )
                  { console.writeline("this is baseclass");}
                   }
                   public class derivedclass: baseclass
                    {public dervedclass(  )
                    console.writeline("this is derivedconstructor");
                    }
                    public static void main( )
                    { derivedclass obj = new derivedclass();
                      obj.hello( ); 
                     }
 OUTPUT : this is baseclass constructor 
         this is  derived constructor
         this is   baseclass 
    
                    

  •   POLYMORPHISM  : When an object exhibits different  behaviour in different situation. In simple way  when a message  can be processed in different ways/forms .   

      Polymorphism is of two types : Compile time polymorphism   (this is concept   

      of  OVERLOADING).      

    Runtime Polymorphism : (this is concept of OVERRIDING).

Sunday, 12 May 2013

HOW TO READ CONNECTION STRING FROM WEB.CONFIG FILES

HOW TO READ CONNECTION STRING  FROM WEB.CONFIG FILES ?


CONFIGURATION MANAGER IS USED TO READ CONNECTION STRING FROM WEB.CONFIG FILE.


For eg : 

 protected void Page_Load (...)          

 { con.ConnectionString = ConfigurationManager.ConnectionString["cn"].ConnectionString; //some code // }



CONNECTION STRING IN ASP.NET AND SQL SERVER

CONNECTION STRING IN ASP.NET 

When a connection is formed between  SQL Server  and ASP.NET  in that case  string  is generated which is known as connection string .

Connection String should be written in that file which does not compile. (the non-compiled file is web.config )


Connection String on Web.Config File : 


<?xml version="1.0"?>

<configuration>

    <system.web>
        <compilation debug="false" targetFramework="4.0" />

    </system.web>
  <connectionStrings>
    <add name="cn"    connectionString="server=servername/instancename;Database=databasename;uid=sa;
     pwd=123 " />
  </connectionStrings>
</configuration>


HOW TO CREATE DATA BASE IN VISUAL STUDIO 2010

HOW TO CREATE DATA BASE  IN VISUAL STUDIO 2010 

STEPS TO CREATE DATABASE: 


Visual Studio 2010 :  This is the start page  for Visual Studio 2010  Professional 



CLICK ON VIEW => CLICK ON SERVER EXPLORER (IS TO MANAGE DATABASES )




RIGHT CLICK ON DATA CONNECTION  => CLICK ON CREATE NEW SQL SERVER DATABASE 





 A new window will  appear : Create New SQL Server  Database



GIVE NAME TO SERVER /GIVE INSTANCE NAME => USE SQL SERVER  AUTHENTICATION => USER NAME :SA PASSWORD : GIVE SOME PASSWORD => NEW DATABASE NAME : GIVE ANY  => OK 






IN SERVER EXPLORER  YOU WILL SEE A NEW DATABASE IS CREATED WITH TEST DATABASE NAME  WHICH INCLUDES FURTHER FILES  AS SHOWN BELOW.










Files Created in DATABASE


Files Created in DATABASE 

Two Types of files are created in Database : 

.mdf :Microsoft Datbase File (This is primary file ) 

.ldf : log database files 


Two types of objects are formed in MDF  : USER DEFINED  AND SECOND IS SYSTEM DEFINED . 

LDF IS BASICALLY FOR STORING AND RETRIEVING DATA .


THESE FILES LDF AND MDF ARE ON DIFFERENT LOCATIONS. 


LDF IS USED FOR SECURITY  PURPOSE  BY DEFAULT IT IS STORED IN ONE FOLDER :  DATA FOLDER  


PROGRAM FILES => MSSQL SERVER => MSSQL => DATA FOLDER =>. MDF AND LDF 



DIFFERENCE BETWEEN RESPONSE.REDIRECT AND SERVER. TRANSFER

DIFFERENCE BETWEEN  RESPONSE.REDIRECT AND SERVER. TRANSFER 

Server.Transfer: 

  • Server.Transfer only works with ASPX pages not HTML pages .  
  • Server.Transfer only works with internal URL not external URL  .
  • In case of Server.Transfer there is no change in URL(FOR SECURITY PURPOSE ) .
  • Server.Transfer is Faster as there is  server process .

Response.Redirect : 

  • Response.Redirect  works with ASPX PAGES as well as HTML pages . 
  • Response.Redirect works with internal URL as well as external URL . 
  • In case of Response.Redirect  we change the URL i.e there is  change in  the URL. 
  • Response.Redirect is  slow process  as  there is client process involved in it. 


Monday, 6 May 2013

DESIGN PATTERNS IN ASP.NET C#

DESIGN PATTERNS IN ASP.NET C# 


The Gang-of-Four (GoF) Design Patterns

CREATIONAL PATTERN  :


  ABSTRACT FACTORY
    BUILDER
   FACTORY METHOD
   PROTOTYPE
  SINGELTON

STRUCTURAL PATTERN 


  ADAPTER
  BRIDGE
  COMPOSITE
  DECORATOR
  FAƇADE
  FLYWEIGHT
  PROXY










 

BEHAVIORAL PATTERN 

  CHAIN OF RESPONSIBILITY
  COMMAND
  INTERPRETER
  ITERATOR
  MEDIATOR
  MEMENTO
  OBSERVER
  STATE
  STRATEGY
  TEMPLATE METHOD
  VISITOR

S.O.L.I.D PRINCIPLES TO DESIGN CLASS IN ASP.NET C#

S.O.L.I.D PRINCIPLES TO DESIGN  CLASS IN ASP.NET C# 

(CONCEPT OF OOPS)

  • The Single Responsibility Principle :  THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE.

  • The Open Closed Principle : SOFTWARE ENTITIES (CLASSES, MODULES, FUNCTIONS, ETC.) SHOULD BE OPEN FOR EXTENSION, BUT CLOSED FOR MODIFICATION. 

  • The Liskov Substitution Principle :   FUNCTIONS THAT USE POINTERS OR REFERENCES TO BASE CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT.

  • The Interface Segregation Principle: CLIENTS SHOULD NOT BE FORCED TO DEPEND UPON INTERFACES THAT THEY DO NOT USE.

  • The Dependency Inversion Principle :  HIGH LEVEL MODULES SHOULD NOT DEPEND UPON LOW LEVEL MODULES. BOTH SHOULD DEPEND UPON ABSTRACTIONS


THIS IS THE MOST IMPORTANT INTERVIEW QUESTION IN ASP.NET C#