Monday, June 28, 2010

Abstract classes

A class which has atleast one abstract method is known as an Abstract class.
! Abstract Method - A method which has only method declaration but no method definition is known as an Abstract method.
! An abstract class cannot be instantiated by the keyword new.
! An abstract class should have atleast one child class, using child class instance variables only we can access abstract class features.
! The base class can be overridden by using 'override' keyword in derived class.
! An abstract method cannot also use the modifiers static or virtual.
! An abstract class cannot be sealed.
! Partially Abstract classes.
! Abstract class features we have to inherit to the child classes.

Inheritance in .Net

Inheritance is the concept of reusability. Using inheritance one class feature we can access in the other classes.
##5 Types of Inheritance

! Single Inheritance - One base class --> One child class directly

! Multilevel Inheritance - Base class --> Child class (d1) --> Child class(d2)

! Hierarchical Inheritance - Base class ---- Child class (c1)
Child class (c2)

! Multiple Inheritance - Base class(b1)
--- Child class
Base class (b2)


! Hybrid Inheritance - Altogether, C# doesn't support Hybrid inheritance always child classes having multiple duplicate copies getting ambiguos error.
To overcome this error we have to work with virtual base classes. Virtual base classes derive only one copy to the child classes.

Difference between Value and Reference DataTypes

##Value Types

Simple variables in a class
Memory allocated on the stack
Primitive data types such as int, interface, event, and delegate.
Their existence is till they are called in a class
System.Valuetype

##Ref types
Needs to be instantiated using a 'new' keyword.
Memory allocated on the heap.
Reference types are data types such as class, char, and float.
They exist for a long period of time.
System.Object

What are Class Methods

Which have Static modifiers -- Methods which are invoked by a class name. They can access class variables & class methods but cannot access instance variables & instance methods.

Access Specifiers -- Scope of the variables

->Public -- Public access modifier can be set to a class / method / property to make it visible to any class / any assembly.
->Private -- Private can be set to those fields which are within the class and they are used to hide from outside of the class.
->Protected -- Protected is used for immediate child classes.
->Internal -- Internal is used specifically for within the assembly.
->Protected Internal -- It is used for within the assembly and assembly that inherits this assembly (Shared Assembly).
->Static @ Modifier -- Static member belongs to the class and as such we don't need to create an object to access it.
->Non-static member - Default, can be accessed only via an object of the class.
Real time: WriteLine() is a static function in Console as we did not create an object that looks like Console to access it.

What are Constructors

! Constructors are similar to methods.
! They always take the name of the class but no return type.
! Constructors cannot be called/ inherited can only be invoked by 'new' operator.
! They allocate memory to all of class/member variables to keep default values in it.
! Class has one single constructor & it is private and can never be instantiated.
! Static Constructors -- Used for initializing only static members of a class..These are invoked very first time class is loaded in memory. No args. No Access Modifiers.
! Non-Static Constructors -- Used for initializing static & non-static methods. Invoked every time a new object is created.

What are Constants in .Net

Constant is a value that remains unchanged in a class.
! They are specific to classes not to objects.

Differences between 'const' and 'read-only' in C#:

'Const': 'Read-only':
•Can't be static. _______________ •Can be either instance-level or static.
•Value is evaluated at compile time. _______________ •Value is evaluated at run time
•Initialized at declaration only. _______________ •Can be initialized in declaration or by code in the constructor.

Methods and Events

Methods - It defines behavior of a class. Main method has one entry point.


Events - Events are specifically for a user action or application action i.e., event is like an action to be performed in an application.

What are Indexers in .Net

They are used to treat an object as an Array.
! Indexers are implemented using 'this' keyword.
! In Indexers the get and set get called with a variable which is the array parameter value.
! A property is identified by its name, an indexer by its signature.
! They can't be static.
! In indexers when we are overriding code in the derived class, we would like to call the original indexer in the base class first.

What are Properties in .Net

Properties are used to expose the values of fields.
! It is like an extension of member variable, where we can check value of variable.
! A property is a member of a class. It behaves like a variable for the user.
! To implement a property in real life, we create a public variable which will hold the value of the property.
! When there is only get accessor, it behaves as const / read only field.
! When there is only set accessor, it behaves as write only field.
! Like variable we access them using the class and not the instance.
! Property or Indexer cannot be of void type.
! Properties can be overridden but not overloaded.

What are fields in .net

A field is very much inside the class. A field is always private.
! Static variables need not be instantiated, Instance variables need to be instantiated.
! Fields are similar to variables.

Members of a Class

  1. Namespace
  2. Fields
  3. Properties
  4. Indexers
  5. Methods
  6. Events
  7. Constants
  8. Constructors
  9. Destructors

Object

Object is like an instance of a class.
! Object occupies normal variables memory.
! Object is physical representation and we can destroy object memory.
! Object having the lifetime, start time is Constructor and end time is Destructor.

Friday, June 25, 2010

Display XML File Data in GridView Control

Focus() method with the TextBox control

Example on Sitemap and Treeview

Showing data in a DataGrid server control with paging enabled

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
</script>
<html><head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True"
OnPageIndexChanged="DataGrid1_PageIndexChanged"></asp:DataGrid>
</form>
</body>
</html>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub BindData()
Dim conn As SqlConnection = New SqlConnection("server=’localhost’;
trusted_connection=true; Database=’Northwind’")
Dim cmd As SqlCommand = New SqlCommand("Select * From Customers", conn)
conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Customers")
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub

Thursday, June 24, 2010

Using the Focus() method with the TextBox control

VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Focus()
End Sub
C#
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Focus();
}

When the page using this method is loaded in the browser, the cursor is already placed inside of the text
box, ready for you to start typing. There is no need to move your mouse to get the cursor in place so you
can start entering information in the form. This is ideal for those folks who take a keyboard approach to
working with forms.

Example for Encapsulation?

Encapsulation in ObjectOriented Approach

The term "encapsulation" is usually used to point up the advantage of Object Oriented method in computer programming approach. It means that in Object-Oriented approach, an object is encapsulated from any other object there is. Everything inside an object, cannot be "touched" (accessed) by any other object within the program, unless it is permitted to be.

So whenever we want any property of an object (constants, variables, functions, or procedures) to be revealed to others, we just have to set it as a "Public" property (usually done by typing the word "Public" in the beginning of its declaration). And when we don't want it to be, we set it as "Private".

And encapsulation is an advantage because as the programming goes on, we don't have to worry about the same constant, variable, function, or procedure's name within the whole program. Every object has its own properties, and can only be accessed if it was allowed.

Thursday, June 17, 2010

How to get user cursor to point to textbox control in a particular page.

when you want to show the user cursor in a particular textbox control. then your code should look like this

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Focus();
}
}

Showing data in a DataGrid server control with paging enabled

Default.aspx.vb

Imports System.Data.SqlClient

Imports System.Data



Partial Class _Default

Inherits System.Web.UI.Page





Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

BindData()

End If



End Sub

Private Sub BindData()

Dim con As SqlConnection

con = New SqlConnection("Data Source=EMMU-PC;Initial Catalog=mendu;Integrated Security=True")

Dim cmd As SqlCommand

cmd = New SqlCommand("select * from mendu1", con)

Dim ad1 As SqlDataAdapter

ad1 = New SqlDataAdapter(cmd)

Dim ds As New DataSet

ad1.Fill(ds)

DataGrid1.DataSource = ds

DataGrid1.DataBind()

End Sub



Protected Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged

DataGrid1.CurrentPageIndex = e.NewPageIndex

BindData()

End Sub



End Class





Default.aspx



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>











Untitled Page

























Tuesday, June 15, 2010

Overriding and Hiding

Overloading
More than one methods have the same name but different signatures

Overriding
Replacing the implementation of a methods in the superclass with one of your own.
  • You can only override a method with the same signature.
  • You can only override non-static methods.
Hiding
Fields and static methods can not be overridden. They can
only be hidden.
  • Hidden fields and static methods are still accessible via references to the superclass.
  • A static method can be only be hidden by another static method.
  • A static variable may be hidden by an instance variable.

Which implementation is used?
  • When invoking a non-static method, the actual class of the object determines. (run-time)
  • When accessing a field, the declared type determines. (compile time)
  • When invoking a static method, the declared type determines. (compile time)

Constructors of Extended Classes

  • The constructor of the super class can be invoked.
  • Super(...) must be the first statement.
  • If the super constructor is not invoked explicitly, by default the no-arg super() is invoked implicitly.
  • You can also invoke another constructor of the same class.

public class ColoredPoint extends Point {
public Color color;
public ColoredPoint(double x, double y,
Color color) {
super(x, y);
this.color = color;
}
public ColoredPoint(double x, double y) {
this(x, y, Color.black); // default value of color
}
public ColoredPoint() {
color = Color.black;
}
}


Default Constructor of Extended Classes

Default no-arg constructor is provided:
public class Extended extends Super {
public Extended() {
super();
}
// methods and fields
}

Execution Order of Constructors

public class Super {
int x = ...; // executed first
public Super() {
x = ...; // executed second
}
// ...
}
public class Extended extends Super {
int y = ...; // executed third
public Extended() {
super();
y = ...; // executed fourth
}
// ...
}

Monday, June 14, 2010

ASP.NET 2.0 Interview Questions

1. What is the name of the property of ASP.NET page that you can query to determine that a ASP.NET page is being requested not data being submitted to web server?
A. FirstGet
B. Initialized
C. IncludesData
D. IsPostBack

IsPostBack

2. While creating a Web site with the help of Visual Studio 2005 on a remote computer that does not have Front Page Server Extensions installed, which Web site type will you create in Visual Studio 2005?
A. Remote HTTP
B. File
C. FTP
D. Local HTTP

Hypertext Transfer Protocol (HTTP)

3. If you want to create a new Web site with the help of Visual Studio 2005 on a Web server that is hosted by your ISP (Internet Services provider) and the Web server has Front Page Server Extensions installed, what type of Web site type would you create in Visual Studio 2005?
A. Local HTTP
B. File
C. FTP
D. Remote HTTP

Hypertext Transfer Protocol (HTTP)

4. For separating server-side code from client-side code on a ASP.NET page, what programming model should you use?
A. Separation model
B. Code-Behind model
C. In-Line model
D. ClientServer model

5. Amit created a new Web site using Visual Studio 2005 in programming language C#. Later, Amit received an existing Web page from his boss, which consisted of the Contact.aspx file with the Contact.aspx.vb code-behind page. What must Amit do to use these files?
A. Amit can simply add the files Contact.aspx, Contact.aspx.vb into the existing Web site, because ASP.NET 2.0 supports Web sites that have Web pages that were programmed with different languages.
B. The Contact.aspx file will work, but Amit must rewrite the code-behind page using C#.
C. Both files Contact.aspx and Contact.aspx.vb must be rewritten in C#.
D. Amit must create a new Web site that contains these files Contact.aspx and Contact.aspx.vb. Set a Web reference to the new site.

6. If you want to make a configuration setting change in your server that will affect to all Web and Windows applications on the current machine. Where you will make the changes?
A. Global.asax
B. Web.config
C. Machine.config
D. Global.asax

7. If you want to make a configuration setting change that will affect only the current Web application. Which file will you change?
A. Web.config that is in the same folder as the Machine.config file
B. Web.config in the root of the Web application
C. Machine.config
D. Global.asax

8. For making a configuration setting change that will affect only the current Web application. Is there any tool that has a user-friendly Graphical User Interface (GUI)?
A. The Microsoft Management Utility
B. Microsoft Word
C. Visual Studio, using the Tools > Options path
D. Web Site Administration Tool

ASP.NET 2.0 Interview Questions
9. How will you identify which event in the ASP.NET Web page life cycle takes the longest time to execute?
A. Turn on ASP.NET trace and run the Web application.
B. Add a few code to each of the page life-cycle events that will print the current time.
C. In the Web.config file, add the monitorTimings attribute and set it to True.
D. In the Web site properties, turn on the performance monitor and run the Web application. After that, open performance monitor to see the timings.

11. You are interested in examining the data that is posted to the Web server. What trace result section can you use to see this information?
A. Control Tree
B. Headers Collection
C. Form Collection
D. Server Variables

12. While creating web site you need to add an HTML Web server control to the Web page, you need to drag an HTML element from the ToolBox of Visual Studio 2005 to the Web page and then which of the following tasks you will perform?
A. Right-click the HTML element and click Run=Server.
B. Double-click the HTML element to convert it to an HTML server control.
C. Right-click the HTML element and click Run As Server Control.
D. Click the HTML element and set ServerControl to true in the Properties window.

13. While testing your ASP.NET web application you noticed that while clicking on CheckBox of one of the web page it does not cause a PostBack; you required that the CheckBox should make PostBack so Web page can be update on the server-side code. How can you make the CheckBox to cause a PostBack?
A. Set the AutoPostBack property to true.
B. Add JavaScript code to call the ForcePostBack method.
C. Set the PostBackAll property of the Web page to true.
D. Add server-side code to listen for the click event from the client.

14. While writing code in Visual Studio 2005 you creates a new instance of a ASP.NET TextBox server control, what do you need to do to get the TextBox to display on the Web page?
A. Call the ShowControl method on the TextBox.
B. Set the VisibleControl to true on the TextBox.
C. Add the TextBox instance to the form1.Controls collection.
D. Execute the AddControl method on the Web page.

15. While creating your ASP.NET web based application you want to create multiple RadioButton server controls which should be mutually exclusive, what property of RadioButton server controls you must set?
A. Exclusive
B. MutuallyExclusive
C. Grouped
D. GroupName

16. While creating an ASP.NET web application with the help of Visual Studio 2005 you are creates a Web page that has several related buttons, such as fast-forward, reverse, play, stop, and pause. There should be one event handler that handles the processes of PostBack from these Button server controls. Other than the normal Submit button, what type of button can you create?
A. OneToMany
B. Command
C. Reset
D. ManyToOne

17. In the Design view in Visual Studio 2005 of an ASP.NET web page, what is the easiest way to create an event handler for the default event of a ASP.NET server control?
A. Open the code-behind page and write the code.
B. Right-click the control and select Create Handler.
C. Drag an event handler from the ToolBox to the desired control.
D. Double-click the control.

18. Which of the following represents the best use of the Table, TableRow, and Table-Cell controls?
A. To create and populate a Table in Design view
B. To create a customized control that needs to display data in a tabular fashion
C. To create and populate a Table with images
D. To display a tabular result set

19. For your ASP.NET web application your graphics designer created elaborate images that show the product lines of your company. Some of graphics of the product line are rectangular, circular, and others are having complex shapes. You need to use these images as a menu on your Web site. What is the best way of incorporating these images into your Web site?
A. Use ImageButton and use the x- and y-coordinates that are returned when the user clicks to figure out what product line the user clicked.
B. Use the Table, TableRow, and TableCell controls, break the image into pieces that are displayed in the cells, and use the TableCell control’s Click event to identify the product line that was clicked.
C. Use the MultiView control and break up the image into pieces that can be displayed in each View control for each product line. Use the Click event of the View to identify the product line that was clicked.
D. Use an ImageMap control and define hot spot areas for each of the product lines. Use the PostBackValue to identify the product line that was clicked.

20. You are writing ASP.NET 2.0 Web site that collects lots of data from users, and the data collection forms spreads over multiple ASP.NET Web pages. When the user reaches the last page, you need to gather all of data, validate the data, and save the data to the SQL Server database. You have noticed that it can be rather difficult to gather the data that is spread over multiple pages and you want to simplify this application. What is the easiest control to implement that can be used to collect the data on a single Web page?
A. The View control
B. The TextBox control
C. The Wizard control
D. The DataCollection control

21. In your ASP.NET 2.0 web application you want to display an image that is selected from a collection of images. What approach will you use to implementing this?
A. Use the ImageMap control and randomly select a HotSpot to show or hide.
B. Use the Image control to hold the image and a Calendar control to randomly select a date for each image to be displayed.
C. Use the AdServer control and create an XML file with configuration of the control.
D. Use an ImageButton control to predict randomness of the image to be loaded based on the clicks of the control.

22. In your ASP.NET web application you want to display a list of clients on a Web page. The client list displays 10 clients at a time, and you require the ability to edit the clients. Which Web control is the best choice for this scenario?
A. The DetailsView control
B. The Table control
C. The GridView control
D. The FormView control

23. While developing ASP.NET 2.0 web application you want to display a list of parts in a master/detail scenario where the user can select a part number using a list that takes a minimum amount of space on the Web page. When the part is selected, a DetailsView control displays all the information about the part and allows the user to edit the part. Which Web control is the best choice to display the part number list for this scenario?
A. The DropDownList control
B. The RadioButtonList control
C. The FormView control
D. The TextBox control

ASP.NET 2.0 Interview Questions
24. While developing ASP.NET 2.0 web application you have a DataSet containing a Customer DataTable and an Order DataTable. You want to easily navigate from an Order DataRow to the Customer who placed the order. What object will allow you to easily navigate from the Order to the Customer?
A. The DataColumn object
B. The DataTable object
C. The DataRow object
D. The DataRelation object

25. Which of the following is a requirement when merging modified data into a DataSet?
A. A primary key must be defined on the DataTable objects.
B. The DataSet schemas must match in order to merge.
C. The destination DataSet must be empty prior to merging.
D. A DataSet must be merged into the same DataSet that created it.

26. You are working with a DataSet and want to be able to display data, sorted different ways. How do you do so?
A. Use the Sort method on the DataTable object.
B. Use the DataSet object’s Sort method.
C. Use a DataView object for each sort.
D. Create a DataTable for each sort, using the DataTable object’s Copy method, and then Sort the result.

27. Which of the following ways can you proactively clean up a database connection’s resources?
A. Execute the DbConnection object’s Cleanup method.
B. Execute the DbConnection object’s Close method.
C. Assign Nothing (C# null) to the variable that references the DbConnection object.
D. Create a using block for the DbConnection object.

29. What event can you subscribe to if you want to display information from SQL Print statements?
A. InfoMessage
B. MessageReceived
C. PostedMessage
D. NewInfo

30. To perform asynchronous data access, what must be added to the connection string?
A. BeginExecute=true
B. MultiThreaded=true
C. MultipleActiveResultSets=true
D. Asynchronous=true

31. Which class can be used to create an XML document from scratch?
A. XmlConvert
B. XmlDocument
C. XmlNew
D. XmlSettings

32. Which class can be used to perform data type conversion between .NET data types and XML types?
A. XmlType
B. XmlCast
C. XmlConvert
D. XmlSettings

Thursday, June 10, 2010

Inheritance and Extended Classes

  • Extended classes are also known as subclasses.
  • Inheritance models the is-a relationship.
  • If class E is an extended class of class B, then any object of E can act-as an object of B.
  • Only single inheritance is allowed among classes.
  • All public and protected members of a super class are accessible in the extended classes.
  • All protected members are also accessible within the package.

When to Overload

When there is a general, non-discrimitive description of the functionality that can fit all the overloaded methodes.

public class StringBuffer {
StringBuffer append(String str) { ... }
StringBuffer append(boolean b) { ... }
StringBuffer append(char c) { ... }
StringBuffer append(int i) { ... }
StringBuffer append(long l) { ... }
StringBuffer append(float f) { ... }
StringBuffer append(double d) { ... }
// ...
}

When all the overloaded methods offer exactly the same functionality, and some of them provide default values for some of the parameters.

public class String {
public String substring(int i, int j) {
// base method: return substring [i .. j-1]
}
public String substring(int i) {
// provide default argument
return substring(i, length - 1);
}
// ...
}

Wednesday, June 9, 2010

Example on Overloading

  • Each method has a signature: its name together with the number and types of its parameters

    MethodsSignatures
    String toString()
    void move(int dx, int dy)
    void paint(Graphics g)
    ()
    (int, int)
    (Graphics)


  • Two methods can have the same name if they have different signatures. They are overloaded.
  • Overloading Example

    Public class Point {

    protected double x, y;

    public Point() {

    x=0.0; y=0.0;

    }

    public Point (double x, double y) {

    this.x=x; this.y=y;

    }

    /**calculate the distance between this point and the other point*/

    public double distance (Point other) {

    double dx=this.x-other.x;

    double dy=this.y-other.y;

    return Math.sqrt(dx*dx+dy*dy);

    }

    /**calculate the distance between this point and (x,y)*/
    public double distance(double x, double y) {
    double dx = this.x - x;
    double dy = this.y - y;
    return Math.sqrt(dx * dx + dy * dy);
    }

    /**calculate the distance between this point and the origin*/
    public double distance() {
    return Math.sqrt(x * x + y * y);
    }
    // other methods
    }

Tuesday, June 8, 2010

Example on Method overriding

VBScript - Dictionary Object

Add an Item
Remove All
Remove
Key exists

Add an Item to Dictionary
Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add "a","Akhila" 'Adds a item and key pair
oDictionary.Add "b","Bhanu"
oDictionary.Add "d","Deepthi"
MsgBox "The number of key/item pairs "&oDictionary.Count
For Each obj in oDictionary
msgbox "The key for "&obj&" and the associated data is "&oDictionary(obj)
Next
Msgbox "The value of key a is "&oDictionary.Item("a")

Determine if a specified key exists in the Dictionary Object
Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add "a","Akhila" 'Adds a item and key pair
oDictionary.Add "b","Bhanu"
if oDictionary.Exists("b") Then msgbox "Key exists in the Dictionary"

Remove a key/item pair from Dictionary Object
Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add "a","Akhila" 'Adds a item and key pair
oDictionary.Add "b","Bhanu"
oDictionary.Add "d","Deepthi"
oDictionary.Remove("b")

Removes all key/item pairs from Dictionary Object
Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add "a","Akhila" 'Adds a item and key pair
oDictionary.Add "b","Bhanu"
oDictionary.Add "d","Deepthi"
oDictionary.RemoveAll

Friday, June 4, 2010

What is Garbage Collections

The >Net Framework's garbage collector manages the allocation and release of memory for your application. Each time you create a new object, the common language runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

Thursday, June 3, 2010

ASP.Net Page Life Cycle

Page Life Cycle Stages:
page request
start
initialization
Load
Postback Even Handling
Rendering
Unload

Page Life Cycle Events:
Pre Init
Init
Init Complete
Pre Load
Load
Control Events
Load Complete
Pre-Render
Save State Complete
Render
Unload

Wednesday, June 2, 2010

What is State management

State management is the process by which you maintain state and page information over multiple requests for the same or different pges.

Types of State Management
There are two types State Management

1. Client-Side State Management
This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator (url), or a cookie. The techniques available to store the state information at the client end are listed down below.

a. View State - Asp.Net uses View State to track the values in the Controls. You can add custome values to the view state. It is used by the Asp.Net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.

b. Control State - If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don't break your control by disabling view state.

c.Hidden fields - Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.

d. Cookies - Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.

2. Server-Side State Management

a. Application State - Application State information is available to all pages, regardless of which user requests a page.

b. Session State - Session State information is available to all paes opened by a user during a single visit.

Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.

Example on Data Cache

What is View State

ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.

View State :- Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.

Example on try and catch

Tuesday, June 1, 2010

Difference between Ref vs. Out

The Ref and Our parameters are quiet similar, both parameters are used to return back some value to the caller of the function. But there is a main difference between this two is when we use the out parameter, the program calling the function need not assign a value to the out parameter before making the call to the function. The same is not true for the reference (ref) type parameter. For a ref type parameter, the value to the parameter has to be ssigned before calling the function. If we do not assign the value before calling the function we will get a compiler error.

Authorization in .Net

Authorization is the process of allowing an authenticated user access to resources. Authentication is always proceeds to Authorization; even if your application lets aonymous users connect and use the application, it still authenticates them as being anonymous.

Authentication in .Net

Authentication is the process of obtaining some sort of credentials from the users and using those credentials to verify the user's identity.