TechShri from Shriniwas Wani

Custom Search

23 January, 2008

Most of Asp.Net

*** Page life Cycle in ASP.Net
PreInit > Init > InitComplete > PreLoad > Load >
Control events >
LoadComplete > PreRender > SaveStateComplete > Render > Unload

Init : Raised after all controls have been initialized and any skin settings have been applied

PreLoad : Use this event if you need to perform processing on your page or control before the Load event.
After the Page raises this event, it loads view state for itself and all controls, and then processes any postback
data included with the Request instance.

Load : calls the OnLoad event method on the Page, then recursively does the same for each child control,
which does the same for each of its child controls until the page and all controls are loaded.

PreRender : Databinding done to controls.
Use the event to make final changes to the contents of the page or its controls.

Render : the Page object calls this method on each control that writes out the control's markup that is sent to the browser.

Unload : Use this event to do final cleanup for specific controls, such as closing control-specific database connections, or finishing up logging
After unload cant modify / you cannot make further changes to the response stream.

**** 6 Types of Validation controls in Asp.Net

CompareValidator -- ControlToValidate ; Operator ; ControlToCompare
RequiredFieldValidator
RangeValidator -- ControlToValidate ,MaximumValue , MinimumValue [ Can check range for string/integer/datetime]
RegularExpressionValidator
CustomValidator
ValidationSummary

*** Controls in ASP.Net

***
The ItemCreated event fires once for every DataWebControlNameItem added to the data Web control.
It fires before the Item's DataItem property is assigned.

The ItemDataBound event also fires once for every
item added to the data Web control, but this event fires after the DataWebControlNameItem's DataItem property is assigned. Finally,

The ItemCommand event fires whenever the Command event for a Button or LinkButton within the data Web control fires.

ItemCreated occurs when each Item in the grid is created, including the
header and footer, but the data is not yet available. Use the ItemDataBound
event if you need access to the data being bound to that item.

*** Example
      void Item_Created(Object sender, DataListItemEventArgs e)
{

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

// Retrieve the Label control in the current DataListItem.
Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");

// Retrieve the text of the CurrencyColumn from the DataListItem
// and convert the value to a Double.
Double Price = Convert.ToDouble(
((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString());

// Format the value as currency and redisplay it in the DataList.
PriceLabel.Text = Price.ToString("c");

}
~~~~~~~~~
Differences between Datagrid, Datalist and Repeater?

1. Datagrid has paging while Datalist doesnt.
2. Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid.
3. A repeater is used when more intimate control over html generation is required.
4. When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radiobuttonlist are used as they involve fewer overheads than a Datagrid.

The Repeater repeats a chunk of HTML you write, it has the least functionality of the three. DataList is the next step up from a Repeater; accept you have very little control over the HTML that the control renders.

DataList is the first of the three controls that allow you Repeat-Columns horizontally or vertically.

Finally, the DataGrid is the motherload. However, instead of working on a row-by-row basis, you’re working on a column-by-column basis. DataGrid caters to sorting and has basic paging for your disposal. Again you have little contro, over the HTML. NOTE: DataList and DataGrid both render as HTML tables by default.

Out of the 3 controls, I use the Repeater the most due to its flexibility w/ HTML. Creating a Pagination scheme isn't that hard, so I rarely if ever use a DataGrid. Occasionally I like using a DataList because it allows me to easily list out my records in rows of three for instance.

~~~~~~~~~~~~~~~~~
Literal Control Vs Label

Literal control does not provide substantial functionality and does not add any HTML elements to the Web page where the Label is rendered as a tag.

Literal does not have style property and you cannot apply any styles, themes and skins.

Both controls are used to display static text on the Web page. The Literal control does not inherit from WebControl

~~~~~~~~~~~~~~~



0 Comments:

Post a Comment

<< Home