ListView control Improvements
ListView control is new databound
control that is released in ASP.Net 3.5. To display data, we need to define 2
mandatory templates, LayoutTemplate and ItemTemplate. In ASP.Net 4.0 version,
the LayoutTemplate is made optional and only defining ItemTemplate will display
the data.
<asp:ListView ID="ListView1"
runat="server"
DataSourceID="SqlDataSource1"
ClientIDMode="Predictable" ClientIDRowSuffix="EmpNo,EmpName">
<ItemTemplate>
<span
style="background-color: #DCDCDC;color: #000000;">EmpNo:
<asp:Label ID="EmpNoLabel"
runat="server" Text='<%# Eval("EmpNo") %>' />
<br />
EmpName:
<asp:Label
ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>'
/>
<br />
Address:
<asp:Label
ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>'
/>
<br />
City:
<asp:Label ID="CityLabel"
runat="server" Text='<%# Eval("City") %>' />
<br />
Country:
<asp:Label
ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>'
/>
<br />
<br />
</span>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource
ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM
[Employees]"></asp:SqlDataSource>
Empty Website project and Cleaner
Web.Config file
Visual Studio 2010 includes a new
project template to create empty ASP.Net 4.0 Web application project (Similar to
Empty Website Template in older version). These empty project templates will
now include Web.Config file which is very clean and simple. Due to so many new
additional features released, the web.config file is overloaded with information on
handlers and modules (for asp.net ajax, etc). To maintain the Web.config easily,
Visual Studio 2010 (from beta 2) includes only entries to identify the target
framework used. Rest of the needed settings are moved to machine.config
file.
Read more about this feature on
Scott’s blog.
Routing in Webforms
Routing is a technique where asp.net
webforms can be accessed with a friendly and descriptive URL’s. Hence, the ugly
URL’s with querystring can now be converted to a meaningful and descriptive
which will be easy to remember and will improve the search engine rank.
Read Rangan’s post on routing here.
CSS Improvements
The other major improvements in ASP.Net
4.0 are on the way the HTML rendered to the client browser. The rendered HTML
will be complaint with latest HTML standards.
Few things will be,
1. A new property called controlRenderingCompatibilityVersion is added
to the Pages element of configuration files.
<pages
controlRenderingCompatibilityVersion="3.5|4.0"/>
The value
“3.5” indicates the controls are rendered in legacy ways. The value “4.0”
indicates the control will be rendered with the latest improvements of 4.0
framework.
2. Till 3.5 framework, setting “Enabled=false” for any control will
render disabled attributes in the HTML for the control. According to the latest
HTML standard the disabled attribute should be set only for INPUT tags. ASP.Net
4.0 addresses this issue by rendering disabled attribute to only INPUT tags and
a CSS class called “aspNetDisabled” to other controls to disable it when
controlRenderingCompatibilityVersion property is set to “4.0”.
Below you
can find a HTML rendered for a Label and TextBox control when
controlRenderingCompatibilityVersion property is set to “4.0”.
<span id="Label1"
class="aspNetDisabled">Label</span>
<input name="TextBox1" type="text"
id="TextBox1" disabled="disabled" />
3. From ASP.Net 2.0, the hidden fields generated for viewstate are
packed inside a div tag for XHTML standard. This leads a small white space on
the page. ASP.Net 4.0 now includes this div with a css class “aspNetHidden”. We
can now define the class to prevent the white space by setting border to
0.
<div
class="aspNetHidden">...</div>
4. Menu controls render markup that is semantically correct and
compliant with accessibility guidelines.
5. Validation controls do not render inline styles.
RabioButtonList and CheckboxList
Changes
From ASP.Net 4.0, the RadioButtonList
and CheckBoxList controls includes 2 more value fro the property
RepeatLayout.
1. OrderedList
The radiobutton/checkbox is rendered as
li elements within an ol element.
2. UnorderedList
The radiobutton/checkbox is rendered as
li elements within an ul element.
|