CODEDIGEST
Home » Articles
Search
 

Technologies
 

Sponsored links
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Most Frequently Used Features of ASP.Net 2.0

By Satheesh babu
Posted On Jul 29,2008
Article Rating:
Be first to rate
this article.
No of Comments: 3
Category: ASP.Net
Print this article.

Most Frequently Used Features of ASP.Net 2.0

Introduction

ASP.Net 2.0 has introduced many useful features which made developers life easier. There are lots of tasks which we will repeatedly do in our projects. Some of these tasks are provided as a readymade feature and are easily available to use with the introduction of ASP.Net 2.0. In this article, I have compiled a list of such useful features that are really helpful in our day to day development activity. Moving forward, we will understand,

Ø       Server Side Comments with ASP.NET 2.0.

Ø       Refreshing ASPX Page Automatically from Server side Meta tags in ASP.Net 2.0.

Ø       Default Button in ASP.Net 2.0.

Ø       SmartNavigation in ASP.Net 2.0.

Ø       Set Focus to a Particular Element.

Ø       Page.Items Collection.

Server Side Comments with ASP.NET 2.0

In ASP.net application, we can comment the HTML code by,

 

<!--  HTML Comments

-- >

When we do this, the browser will omit displaying the contents between <!—-and --> block but the actual contents inside this block will be parsed, executed by the asp.net engine and the output will be sent to the browser. ASP.Net 2.0 answered this issue by introducing a new feature to comment the server side elements.This server side comments will prevent the asp.net to parse and execute the contents.

 

<%-- Server side comments --%>

 

For example, the below commented statements will not be parsed by ASP.Net engine during the page processing.

 

<%--

<asp:TextBox CssClass="stocktextfont" ID="txtChildNumber" runat="server" ReadOnly="True" BackColor="#FFE0C0"

Width="232px" TabIndex="4"></asp:TextBox>

 

--%>

The output html will not have the markup generated for the above textbox.

 

Refreshing ASPX Page Automatically from Server side Meta tags in ASP.Net 2.0

With the introduction of ASP.Net 2.0, we can set meta tags dynamically from codebehind class using HtmlMeta class. To refresh our aspx page from the codebehind class we can use the following code,

 

HtmlMeta meta = new HtmlMeta();

HtmlHead head = (HtmlHead)Page.Header;

meta.HttpEquiv = "refresh";

meta.Content = "5";

head.Controls.Add(meta);

 

 

Default Button in ASP.Net 2.0

ASP.Net 2.0 has a property called default button in <form> tag and in Panel control. This enables the user to submit the form when the user hits enter.

 

<form id="form1" runat="server" defaultbutton="btnSave">

 

and

 

<asp:Panel ID="Panel1" DefaultButton="btnSave" runat="server"></asp:Panel>

 

Setting this attribute in form tag makes the default button globally to that page and setting the default button attribute in Panel controls submits page when the user hits enter key inside the panel control.

 




SmartNavigation in ASP.Net 2.0

Smart navigation enables a webform to maintain its focus on postback when the webform content is lengthy and also it prevents flickering of screen. Smart navigation only works on IE 5 and above. We can either set the smart navigation on page level or project level. In earlier versions of ASP.Net, it can be set by SmartNavigation property of Page object.

 

On page level it, can be enabled by setting SmartNavigation="true" in @Page attribute.

 

This feature can be enabled across the project by setting it in web.Config file.

<system.web>

<pages smartnavigation="true">

</system.web>

 

With the release of ASP.Net 2.0, SmartNavigation property is considered as obsolete and it is replaced by a property called MaintainScrollPositionOnPostBack.

 

Page.MaintainScrollPositionOnPostBack = true;

 

OR

 

<%@ Page Language="C#" AutoEventWireup="true" MaintainScrollPositionOnPostback="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

In Web.Config,

<system.web>

<pages MaintainScrollPositionOnPostback="true"/>

</system.web>

 

Set Focus to a Particular Page Element

We can set the browser focus to a particular element in ASP.Net 2.0. The below code will help us to achieve that.

Page.SetFocus(TextBox1); //Takes a Page control

OR

Page.SetFocus("TextBox1"); // Takes a control Client ID

 

Page.Items Collection

The Page object has a new collection called Page.Items, which can be used to hold objects and can be retrieved back for accessing in the later page events.  One another use of this collection is, we can pass objects to user controls by adding the object in Items Collection of the Page object from the ASPX page. Its lifetime will be equivalent to the current request's life time.

ASPX page

Page.Items.Add("EmpObje", _emp);

Usercontrol

Employee emp = Page.Items["EmpObje"] as Employee;

 

Conclusion

There are so many handy features given by ASP.Net 2.0 which can be used extensively in our day to day activities. This article will help us understanding some of the extensively used features which the 2.0 framework provided us. Most of us are still following same old way of achieving these tasks without recognising these readymade features in ASP.Net 2.0. These new features in asp.net 2.0 will reduce our development time by preventing us to write our custom code for the repeatedly done tasks.

Happy Coding!!

Similar Articles
You can contribute to CodeDiget.Com:
Donate to CodeDigest.com
Article Feedback
Comments
Nice Article
Nice article from Codedigest
thanks for this
Pawan Kumar
for development solution visit:
http://dev.codeplatter.com
Nice
Really Useful
a
Good one man!!!! it is realy useful.