Visual Studio Beta 1 and the. NET Framework Beta 1 have been released for some time, and I should have written this article long ago. ASP.net 4.0 has improved many different sets of scenarios (set of scenarios), such as WebForms, Dynamic data, and AJAX based Web development. There are also many improvements to the core runtime environment that supports asp.net, such as caching, session, and Request/response objects.
In this article, we'll examine some of the improvements to the Web form. This is a lot of improvement, and we will experience more of this improvement in subsequent articles.
Using the ViewStateMode property to control view state-performance enhancements
One of the most popular flaws in asp.net WebForm is the increasing viewstate effect on performance. Although you can set the EnableViewState property to True or false before, some controls inherit by default, and even if you set it to enabled on the control layer, there is an inconsistent behavior.
In ASP.net 4.0, the ViewStateMode property helps determine whether each control's viewstate should be enabled, disabled, or inherited. For example:
<asp:panel id= "pnlviewstate" runat= "Server" viewstatemode= "Disabled" >
Disabled: <asp:label id= "Label1" runat= "Server" text= "Value set in Markup" Viewstatemode= "Inherit"/><br/>
Enabled: <asp:label id= "Label2" runat= "Server" text= "Value set in Markup" viewstatemode= "Enabled"/>
<asp:button id= "Button1" runat= "server" text= "postback"/>
</asp:Panel>
Back-end Code
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Label1. Text = "Value set in code behind";
Label2. Text = "Value set in code behind";
}
}
Running this page, you will find that the initial value of the two tags is set to "value set in code behind", and after the click button (postback), the Label1 values become "value set in markup", and the Label2 value remains unchanged. As you can see, the panel that holds the two tabs sets ViewStateMode to Disabled, Label1 inherits this setting (this is the default if not specified), and Label2 is set to enable. That's why Label2 kept viewstate and Label1 lost.
Although it can be said before the use of simple enableviewstate properties, but has been unstable. Think of us at most performance seminars (performance session) and say that if the ViewState doesn't work, disable it and then set it to boot in the control layer. The introduction of this viewstatemode can be said to be a very good structural change that will help improve performance (architectural changes).
Web page meta keyword and description-Search engine optimization features
In Visual Studio 2008, you can set the title of a Web page by either declaring it directly or using Page.title in your program. With more and more traffic through search engines, page titles, keywords and descriptions become more important. Although many search engines have been overlooked because of the misuse of the keywords, the page description is the basis for identifying and indexing the content of the Web page google,bing these mainstream search engines.
Asp. NET new feature 4.0 allows users to programmatically set page descriptions and keywords as follows:-
protected void Page_Load (object sender, EventArgs e)
{
This. Page.title = "my asp.net Blog";
This. Page.metakeywords = "asp.net, Web Development, blog, asp.net blog";
This. Page.metadescription = "This Blog contains posts related to asp.net and Web Development";
}
The code above will produce the following markup:
<meta name= "keywords" content= "asp.net, Web Development, blog, asp.net blog"/>
<meta name= "description" content= "This Blog contains posts to related and Web asp.net" Development
The mechanism is that if the META tag already appears in the HTML tag, the content set in the program will be filled in as long as the Name property is the same.
Although this may seem simple, this is useful if you want to set them dynamically based on certain conditions or criteria. Currently, these are statically set in the HTML code. Now, with the page class at this level of access, they can be set up dynamically.
There are many other improvements to webforms, such as routing enhancements, ClientID settings, and so on, which we will explain in one by one of the following articles.
Let's cheer!