Skip to main content

Professional ASP .Net page 3

· @ Page Directive

This directive is used to assign page-specific attributes that are used by the web forms page parser and compiler. It can be placed anywhere in the page. A page can have only one @ Page directive.

· @ Register Directive

This directive is used to register a user or server custom control on the page.

1) To register a user control use:

<%@ Register TagPrefix = "Wrox" TagName="CButton"

Src = "UserControls\Header.ascx" %>

To use the control:

Source file of a user control can have only one control.

2) To register a custom server control: These custom controls are compiled and contained within assemblies.

<%@ Register TagPrefix = "Wrox" Namespace = "WroxControls"

Assembly = "RatingMeter" %>

To use the control:

· @ Assembly Directive

This directive is used to refer an assembly for the page.

1) To use a compiled assembly: <%@ Assembly Name="xyz" %>

2) To use a source file that will be compiled when the page is compiled: <%@ Assembly Src="pathname" %>

This tag is usually not required, as any assembly that is in the ASP .Net application's bin directory will automatically be compiled into the page. Use this when you refer any shared assembly or the assembly in another folder.

· @ OutputCache Directive

This directive is used to control how the page is cached. When caching for the page is enabled, the requested page is compiled for the first request and all the subsequent requests (even from another user) is served from that compiled cached page. The attributes for the directive are:

1) Duration: This attribute is used to control how long an item will stay in the cache before being invalidated. This is a mandatory attribute.

2) Location: This attribute specifies where the caching is stored. It can be Any, Client, Downstream, Server on None.

3) VaryByCustom: When the value of this attribute is set to "browser", caching is varied by the type of browser.

4) VaryByParam: This attribute is used to vary the cache, based on the values of parameters passed to the server (i.e. QueryString parameter). Value for this attribute can be * (for all parameters) or none (do not vary on any parameters).

Output caching only works using ASP .Net on the windows 2000 and windows XP platform.

· The principle of code-behind is to create a class for the code, and inherit this class from the ASP .Net Page object. You can then create the ASP .Net page and use a page directive to inherit from the newly created class.

· Smart Navigation

This is an Internet Explorer specific feature, which requires IE 5 or above. Smart navigation has four feature as No more screen flash, Scroll position maintained, Element focus maintained, Last page in History maintained. Smart navigation only redraws the contents of the page that has been changed during a post-back. Entire page does not need to be redrawn. You can enable smart navigation at page level as: <%@ Page SmartNavigation="true" %> or in Web.config as: <pages smartNavigation="true" />

· User Control

A user control does not have a BODY and FORM tag. A source file of a user control has an extension .ascx. To use a user control on a page you have to first register it and then you can use it as a normal control.

When you have a property defined in a user control, you can use it like: (Say you have a property named ConnectionString)

<Wrox:shipment ConnectionString="" runat="server" />

Event for a user control must be handle in the user control page, not on the page hosting the user control. Because the user control's event will not be passed to the hosting page, so the events will never be processed.

· Partial Page Caching

This is also known as fragment caching. It is available when you are using a user control on a page. You can compile and cache that user control first time the hosting page is requested, than on subsequent requests for the hosting page that cached user control is used to render the page. Enabling a caching for the user control is same as a normal page. Use @ OutputCache directive on the user control page.

· Adding the runat="server" attribute to an HTML element causes that control to be compiled into the page, and executed on the server each time the page is requested. It means runat="server" attribute makes a normal HTML element a server control. So, to be able to access the element's properties, method, or events in the server-side code, you have to create it as a server control.

· The base class for the all HTML control is:

System.Web.UI.HTMLControls.HTMLControl

· Each server side event handler has two parameters. The first parameter is a reference to the object that raise the event and the second parameter is a type of EventArgs object that contains any additional information about the event.

· When using ASP .Net's validation control you can check the page's IsValid property to check whether the page passed the validation test or not. You can also use the CausesValidation="false" property of a control (such as a cancel button), so that it can post back the page without occurring the validation process on the client side. Without this you won't able to post back the page without passing all the validation check.

· The ASP .Net Web Form controls are inherited from System.Web.UI.WebControls.WebControl

· Setting Size Of The Control

You can use one of three methods:

1) MyControl.Height = Unit.Pixel(1000)

2) MyControl.Height = Unit.Point(100)

3) MyControl.Height = Unit.Percentage(50)

· The last method sets the controls height to be 50% of the page or container's height.

· When you set AutoPostBack property of a web control is true, on rendering the page in to HTML compiler adds a client-side event to the control's tag. On firing the event a JavaScripts function is called at client side. This function collects the id and values of the control and sends it to server automatically.

· A PlaceHolder control is used to host any other control. You can use a PlaceHolder control to create the other control dynamically and places them into a PlaceHolder control. To add the control at runtime use: MyPlaceHolder.Controls.Add(TBox1).

· DropDownList (a type of ComboBox), ListBox and DataGrid are the most common data controls used in ASP .Net.

· Repeater, DataList and DataGrid are the controls that support templates.

· DataBinder object's Eval method is used to format a field of a data control. <%# DataBinder.Eval (Container.DataItem, "BookDate", "{0:D}") %>. The Eval method carries a noticeable performance overhead, because it uses a technique called late-bound reflection to evaluate the expression. You can format values when you retrieve them from database, it will definitely increases the performance as compared to Eval.

· Binding The Control With Array

MyControl.DataSource = MyArray

MyControl.DataBind()

· Binding The Control With DataView

MyControl.DataSource = MyDataView

MyControl.DataTextField = "Title" ' For display

MyControl.DataValueField = "ISBN" ' For retrieving

MyControl.DataBind()

· Binding The Control With DataSet

MyControl.DataSource = MyDataSet

MyControl.DataMember = "Books" ' Name of the table

MyControl.DataTextField = "Title" ' For display

MyControl.DataValueField = "ISBN" ' For retrieving

MyControl.DataBind()

· Binding The Control With DataReader

You can bind a DataReader to a control as same way as DataView. But you cannot create a single DataReader object and bind it to all the controls on the page.

· Using Templates With Data-Bound Controls

We define four templates for a Repeater control. Note that template definitions don't have to be placed in any particular order within the control definition.

Some of the latest Wrox books

<img src="images/redrule.gif">

<>&<%# Container.DataItem("Title") %&></b>

ISBN: <%# Container.DataItem("ISBN") %>

Title: <%# Container.DataItem("Title") %>

For more information visit

http://www.wrox.com>http://www.wrox.com

Comments

Popular posts from this blog

Top Open Source Web-Based Project Management Software

This is an user contributed article. Project management software is not just for managing software based project. It can be used for variety of other tasks too. The web-based software must provide tools for planning, organizing and managing resources to achieve project goals and objectives. A web-based project management software can be accessed through an intranet or WAN / LAN using a web browser. You don't have to install any other software on the system. The software can be easy of use with access control features (multi-user). I use project management software for all of our projects (for e.g. building a new cluster farm) for issue / bug-tracking, calender, gantt charts, email notification and much more. Obviously I'm not the only user, the following open source software is used by some of the biggest research organizations and companies world wild. For example, NASA's Jet Propulsion Laboratory uses track software or open source project such as lighttpd / phpbb use re

My organization went through the approval process of supporting the .NET Framework 2.0 in production. Do we need to go through the same process all...

My organization went through the approval process of supporting the .NET Framework 2.0 in production. Do we need to go through the same process all over again for the .NET Framework 3.0? Do I need to do any application compatibility testing for my .NET Framework 2.0 applications? Because the .NET Framework 3.0 only adds new components to the .NET Framework 2.0 without changing any of the components released in the .NET Framework 2.0, the applications you've built on the .NET Framework 2.0 will not be affected. You don’t need to do any additional testing for your .NET Framework 2.0 applications when you install the .NET Framework 3.0.

Google products for your Nokia phone

Stay connected with Gmail, Search, Maps and other Google products. Check products are available for your Nokia phone Featured Free Products Search - Find the information you need quickly and easily Maps - Locate nearby businesses and get driving directions Gmail - Stay connected with Gmail on the go YouTube - Watch videos from anywhere Sync - Synchronize your contacts with Google