Whidbey
ASP.NET V2.0 New Features
In this article, we are going to see the new features
of Whidbey ASP.NET V2.0. This is just the tip of the ice berg. Whidbey
ASP.NET V2.0 comes with whole lot of new features. I will keep
updating this article, as and when I find any new features in ASP.NET
V2.0. Here is the some of the new features which i found
interesting.
Cross-page posting
In Whidbey, you will be able to post Web Forms to pages other
than the page on which the input is entered. Postback target is chosen based on
the PostTargetUrl attribute of a control that causes a postback. On the
target page, you will be able to access all of the controls, viewstate, etc. of
the page that caused the web form post. Whidbey passes a page object
called PreviousPage to the current page for accessing controls,viewstate
and all others contents of previous page. For example consider you
are filling your personal details in one page and then you need to post
this details to next page for processing. In ASP.NET v1.0 you need to post this
values to that same page and then you need to redirect to the next page. But in
Whidbey you can directly post this values to the next page.
Page1.aspx
<form runat="server">
<asp:label id="Label1"
runat="server">Name</asp:label>
<asp:textbox id="TextBox1"
runat="server"></asp:textbox>
<asp:button id="Button1" runat="server" text="Button"
posttargeturl="CrossPage.aspx" />
</form>
Page2.aspx.vb
Private Sub Page_Load(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Label1.Text =
DirectCast(PreviousPage.FindControl("TextBox1"),
System.Web.UI.WebControls.TextBox).Text
End Sub
ValidationGroups
You
can now have validator controls optionally validate depending on which button
on the page is pushed. You can group validation rules into “groups“ so that all
controls within that group fire or don't fire.The new feature validation groups
allows you to logically group a set of validation controls, and only validate
the fields that are in the group to which belongs the postback control that the
user clicks. Uses the ValidationGroup attribute to implement in declarative
tags. The key here is that you can have two sets of form fields that aren't
typically used together, and implement validation on both sets of fields,
without the non-used fields causing the page to fail validation. This feature
is very useful in the page where you are having two sets of forms for example
you might have a page which has search pane in the top and the
registration details at the bottom. when find button is clicked you need
to validate only the search page controls and similarly when you press create
login, you need to validate the controls in registration form. For this type of
requirement, this validation groups is very useful. In our example, we have two
textbox and two buttons. When one button is pressed we need to validate
only one textbox and similarly for other button. Each button has
validationgroup attribute set to particular groups which will validate
only one textbox.
<form runat="server">
<asp:label id="Label1"
runat="server">Name</asp:label>
<asp:label id="Label2"
runat="server">Address</asp:label>
<asp:textbox id="TextBox2"
runat="server" ></asp:textbox>
<asp:button id="Button1"
runat="server" text="CheckAddress" validationgroup="Group2" />
<asp:button id="Button2"
runat="server" text="CheckName" validationgroup="Group1" />
<asp:textbox id="TextBox1"
runat="server" validationgroup="Group1,Group2"></asp:textbox>
<asp:requiredfieldvalidator
id="RequiredFieldValidator1" runat="server" errormessage="Required
Field" validationgroup="Group2"
controltovalidate="TextBox2">*</asp:requiredfieldvalidator>
<asp:requiredfieldvalidator
id="RequiredFieldValidator2" runat="server"
errormessage="Required Field" validationgroup="Group1"
controltovalidate="TextBox1">*</asp:requiredfieldvalidator>
</form>
Wizard UI
New <asp:wizard> control that enables
step-by-step wizard UI, for example for gathering multiple pages of input for a
single purpose before saving or processing the input. The Wizard control
defaults to a Next/Previous UI, but is also templated, so you can customize the
UI to your needs. In ASP.NET v1.1, if you want to fill lots of details either
you need to place all the controls in one page or create multiple pages for
groups of controls for providing wizard kind of approach. But in whidbey you
have a new control called Wizard control which will do this type of work with
one page but providing wizard kind of approach. Check out the following code
and find out how easy to create wizard in ASP.NET V2.o
<asp:wizard
id="Wizard1" runat="server" sidebarenabled="false">
<stepnavigationtemplate >
<asp:button runat =server id =stepnextbutton text="Next" />
<asp:button runat =server id =steppreviousbutton text="Previous" />
</stepnavigationtemplate>
<wizardsteps>
<asp:wizardstep runat="server" title="Name ">
Step 1 : Fill your Name <asp:textbox runat="Server"
id="txtNAme"></asp:textbox>
</asp:wizardstep>
<asp:wizardstep runat="server" title="Address Details">
Step 2 : Fill your Address <asp:textbox runat="Server"
id="txtAddress"></asp:textbox>
</asp:wizardstep>
</wizardsteps>
</asp:wizard>
You can find new tags like
<ASP:Wizard>,<stepnavigationtemplate>,<wizardsteps>,<asp:wizardsteps>.
Using stepnavigationtemplate you can define the controls that needs to be
placed in the navigation template. For example you need to place two button
controls and then set id for the controls as stepnextbutton and
steppreviousbutton. Then automatically navigation feature will be there for you
wizards. For putting controls in each step you can use wizardsteps tag.
ASP.NET Themes
A theme is a collection of property settings that
allow you to define the look of pages and controls and then apply the look
consistently across pages. You can apply theme settings to an entire
application (Web site), to a page and its controls, or to an individual
control. If you take popular websites like yahoo they have implemented theme in
their site, for example you need to have theme of yellow color. Then you will
view that website in yellow color if you want to change to red, then all the
controls will change to red. ASP.NET makes available some predefined themes
(global themes) that can be applied to any ASP.NET Web application. For
example, ASP.NET includes a theme called BasicBlue that defines a common style
for most ASP.NET Web server controls.You can create your own themes, called
page themes, to apply to your site or to individual pages.
ASP.NET Site Navigation
When you create Web applications that consist of
anything more than a few pages, you will find it useful to provide a consistent
way for users to navigate around the site. One solution is to include
hyperlinks within pages that allow users to jump to other pages. However, if
your site becomes large and as you move pages in the site, it quickly becomes
difficult to manage all the links. To create consistent, easily managed
navigation for your site, you can use ASP.NET site navigation. If you take this
website you can see site navigation bar at the left side. This site navigation
can be created with very minimal code using following two new controls ,
SiteMapPath control: This control
displays a navigation path (also known as a breadcrumb or eyebrow) that shows
the user the current page location and displays links as a path back to the
home page. The control provides many options for customizing the appearance of
the links.
TreeView controls: This control
displays a tree structure, or menu, that users can traverse to get to different
pages in your site.
URL Rewriting/Mapping
New built-in module for rewriting paths. With this new
feature you can map url's to aspx pages in web.config file.
This feature can be used to hide the url from the user. If you need to
change the location of your aspx page, then you no need to worry. Just change
your url mappings in web.config. Since user is exposed to a url which
doesnt change you wont get 404 error. Web.config setting for urlmapping is as
follows.
<urlMappings enabled="true">
<add url=
"~/UrlMappings.aspx"mappedUrl="~/CrossPage.aspx?From=UrlMappings" />
</urlMappings>
If you are requesting for UrlMappings.aspx, then
actually you will get the response of Crosspage.aspx. But the user will think
that he is getting UrlMappings.aspx only. If you change the Crosspage.aspx
location also, you only need to change this setting in web.config.
Site Counters
This feature can be used to montior a web site. For
example if you want to know during certain time if you want to know how many
hits is made to a particular virutal folder or file. Then you can use this
feature. This services exposes many API's like
GetTotalCount,GetRows,GetTotalNavigateUrlCount,etc for monitoring a website.
Can also be accessed through attributes (CountClicks, CounterGroup, etc.) on
declarative tags, as well as through web.config. Using this feature you can
efficiently log or report page hits,button click in a page or any other events.
For enabling Site counters, you need to place following code in web.config
<siteCounters enabled="true">
<pageCounters enabled="true">
<pagesToCount trackPageUrl="true">
<add path="/" />
</pagesToCount>
</pageCounters>
</siteCounters>
Client Script Goodies
Server buttons now have an OnClientClick attribute
for client-side handling. Focus mechanisms are now built into the page and
controls. A page can also have a default button and a default focused
control. All these features emit the appropriate client-side script. There
will also be automatic scroll position maintenance in the beta release of
Whidbey. Here are few examples
<asp:button
Text=“Save" OnClick=“Button1_Click”
OnClientClick=“Save();” runat=“server” />
<form DefaultFocus=“textbox1” runat=“server”>
No-compile Pages
In web.config, you can configure at the page and
folder level whether pages can be compiled after they've been deployed.
You can set the compilation option even at page directive. If compilation
is disabled, any change to the page after the page or directory has been
locked down will throw an exception.
<system.web>
<pages compilationMode=“Never”/>
</system.web>
Various options for Compilation mode are Never,Auto
and Always.
Image Generation
New feature for generating images in Whidbey. Includes
an HttpHandler (.asix) providing a custom handler and base class for image
generation, including support for downlevel rendering. Also includes a new
DynamicImage control that uses callbacks with the image generation handler to
pull down dynamically generated files. .asix files use the @ Image directive
and inherit from System.Web.UI.Image.ImageGenerator. Does not require
registering your own custom HttpHandler for image generation. Just write the
code.
The <asp:dynamicimage> control supports
databinding. You can bind its imagebytes property to a data column that
contains binary image data. Using the new Image Generation Service and
asp:DynamicImage server control. Show databinding a photo-album where all
images are stored in the database, and bound to the asp:DynamicImage control
within a asp:DataList template.
File System Provider
It allows Web content (both compiled and
non-compiled) to be stored in non-filesystem locations such as databases
or CMS, and even use Sql Cache invalidation to output cache stored
content, while always getting the updated content if it changes. Pretends
to be the filesystem and provides an interface into whatever storage
location the content is actually stored in. Cannot store assemblies, but
can store just about any other content.
Download Sourcecode
ASP.NET WHIDBEY Related Links
-
ASP.NET Whidbey Home Page
-
VB.NET Whidbey Home Page
Page Cycle in ASP.NET V2.0
Master Pages in ASP.NET V2.0
Code-Beside Replaces Code-Behind in ASP.NET V2.0
Reference Links
-
Scott Gu's Blog on ASP.NET 2.0 Tips and Tricks
|