Static variables are stored in special area inside Heap known as High Frequency Heap.
***Incomplete***
Friday, March 25, 2011
Notes on Validation Controls
SetFocusOnError property on a validation control: This property, if set to True, causes the Web control the validation control is operating on to receive focus if the validation control is invalid. This is a nice little usability touch that your users will likely appreciate.
EnableClientScript property on validation control:Leaving the default value (true) of EnableClientScript is a first line of defense, good for 90% of situations. Leaving EnableClientScript as default or setting it to true avoids a postback. If you look at the page source with property setting EnableClientScript="false", you will see some javascript that does the client side validation without posting back. If you look at the page source with property setting EnableClientScript="true", you will see not see any javascript in the source.
You should also check the value of Page.IsVaild in your code behind to handle situations in which the client disabled JavaScript or otherwise circumvented your client-side validation
In Fritz Onion's Essential ASP.NET book:
"As soon as you place a validation control on a page, it is imperative that you check the IsValid flag of the Page class before using any of the data posted by the client. It is a common misconception that if validation fails on a page, the code for that page will not execute. On the contrary, the only thing that happens when server-side validation fails is that the IsValid flag of the Page class is set to false, and each validation control that failed renters itself as a visible span so that the error indicator shows up when the page is redisplayed to the user."
EnableClientScript property on validation control:Leaving the default value (true) of EnableClientScript is a first line of defense, good for 90% of situations. Leaving EnableClientScript as default or setting it to true avoids a postback. If you look at the page source with property setting EnableClientScript="false", you will see some javascript that does the client side validation without posting back. If you look at the page source with property setting EnableClientScript="true", you will see not see any javascript in the source.
You should also check the value of Page.IsVaild in your code behind to handle situations in which the client disabled JavaScript or otherwise circumvented your client-side validation
In Fritz Onion's Essential ASP.NET book:
"As soon as you place a validation control on a page, it is imperative that you check the IsValid flag of the Page class before using any of the data posted by the client. It is a common misconception that if validation fails on a page, the code for that page will not execute. On the contrary, the only thing that happens when server-side validation fails is that the IsValid flag of the Page class is set to false, and each validation control that failed renters itself as a visible span so that the error indicator shows up when the page is redisplayed to the user."
Wednesday, March 23, 2011
Improving performance
1. ScriptManager control has LoadScriptsBeforeUI property which you can set to “False” in order to postpone several script downloads after the content is downloaded. This adds the script references end of the tag. As a result, you see the content first and then the additional scripts, extenders, ACT scripts get downloaded and initialized.
< asp:ScriptManager ID =”ScriptManager1″ runat =”server” EnablePartialRendering =”true” LoadScriptsBeforeUI =”false”> … asp:ScriptManager >
http://omaralzabir.com/fast_page_loading_by_moving_asp_net_ajax_scripts_after_visible_content/
2. Configure Compression (IIS 6.0)
To more efficiently use available bandwidth, it is advisable to enable IIS's HTTP compression feature. HTTP compression provides faster transmission time between compression-enabled browsers and IIS regardless of whether your content is served from local storage or a UNC resource. You can compress static files only, application response files only, or both static files and application response files. Compressing application response files is usually called dynamic compression.
Read this msdn link on how to enable compression
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/92f627a8-4ec3-480c-b0be-59a561091597.mspx?mfr=true
3. Do Not Use the Sp_ Prefix for Custom Stored Procedures
SQL Server always looks in the master database for a stored procedure that begins with the sp_ prefix. SQL Server then uses any supplied qualifiers such as the database name or owner. Therefore, if you use the sp_ prefix for a user-created stored procedure, and you put it in the current database, the master database is still checked first. This occurs even if you qualify the stored procedure with the database name. To avoid this issue, use a custom naming convention, and do not use the sp_ prefix.
4. View state can impact web pages dramatically, not only in page size but also in server side performance. Moreover, pages with large view states can throw unexpected errors. Disable viewstate when there is no need to persist state across postbacks.
consider disabling view state in these cases:
If the controls value is hard-coded.
If the controls value is assigned on every page.
5. Avoid long control names; especially ones that are repeated in a DataGrid or Repeater control. Control names are used to generate unique HTML ID names. A 10-character control name can easily turn into 30 to 40 characters when it is used inside nested controls that are repeated.
6. Something very interesting I came across while reading msdn is to "remove characters such as tabs and spaces that create white space before you send a response to the client. Removing white spaces can dramatically reduce the size of your pages. The following sample table contains white spaces.
// with white space
<table>
<tr>
<td>hello<td>
</td>world</td>
</tr>
</table>
The following sample table does not contain white spaces.
// without white space
<table<<tr><td>hello</td><td\>world</td></tr></table>
Save these two tables in separate text files by using Notepad, and then view the size of each file. The second table saves several bytes simply by removing the white space. If you had a table with 1,000 rows, you could reduce the response time by just removing the white spaces. In intranet scenarios, removing white space may not represent a huge saving. However, in an Internet scenario that involves slow clients, removing white space can increase response times dramatically. You can also consider HTTP compression; however, HTTP compression affects CPU utilization.
You cannot always expect to design your pages in this way. Therefore, the most effective method for removing the white space is to use an Internet Server API (ISAPI) filter or an HttpModule object. An ISAPI filter is faster than an HttpModule; however, the ISAPI filter is more complex to develop and increases CPU utilization. "
Now I need to figure out how to write an ISAPI filter to remove white space.
7. Install Runtime Page Optimizer (RPO). Refer to http://www.iis.net/community/default.aspx?tabid=34&g=6&i=1716. There is a price to it.
Or Write your own optimizer. You can start by reading this blog http://www.darkside.co.za/archive/2008/03/03/web-page-optmisation-using-httpmodule.aspx.
< asp:ScriptManager ID =”ScriptManager1″ runat =”server” EnablePartialRendering =”true” LoadScriptsBeforeUI =”false”> … asp:ScriptManager >
http://omaralzabir.com/fast_page_loading_by_moving_asp_net_ajax_scripts_after_visible_content/
2. Configure Compression (IIS 6.0)
To more efficiently use available bandwidth, it is advisable to enable IIS's HTTP compression feature. HTTP compression provides faster transmission time between compression-enabled browsers and IIS regardless of whether your content is served from local storage or a UNC resource. You can compress static files only, application response files only, or both static files and application response files. Compressing application response files is usually called dynamic compression.
Read this msdn link on how to enable compression
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/92f627a8-4ec3-480c-b0be-59a561091597.mspx?mfr=true
3. Do Not Use the Sp_ Prefix for Custom Stored Procedures
SQL Server always looks in the master database for a stored procedure that begins with the sp_ prefix. SQL Server then uses any supplied qualifiers such as the database name or owner. Therefore, if you use the sp_ prefix for a user-created stored procedure, and you put it in the current database, the master database is still checked first. This occurs even if you qualify the stored procedure with the database name. To avoid this issue, use a custom naming convention, and do not use the sp_ prefix.
4. View state can impact web pages dramatically, not only in page size but also in server side performance. Moreover, pages with large view states can throw unexpected errors. Disable viewstate when there is no need to persist state across postbacks.
consider disabling view state in these cases:
If the controls value is hard-coded.
If the controls value is assigned on every page.
5. Avoid long control names; especially ones that are repeated in a DataGrid or Repeater control. Control names are used to generate unique HTML ID names. A 10-character control name can easily turn into 30 to 40 characters when it is used inside nested controls that are repeated.
6. Something very interesting I came across while reading msdn is to "remove characters such as tabs and spaces that create white space before you send a response to the client. Removing white spaces can dramatically reduce the size of your pages. The following sample table contains white spaces.
// with white space
<table>
<tr>
<td>hello<td>
</td>world</td>
</tr>
</table>
The following sample table does not contain white spaces.
// without white space
<table<<tr><td>hello</td><td\>world</td></tr></table>
Save these two tables in separate text files by using Notepad, and then view the size of each file. The second table saves several bytes simply by removing the white space. If you had a table with 1,000 rows, you could reduce the response time by just removing the white spaces. In intranet scenarios, removing white space may not represent a huge saving. However, in an Internet scenario that involves slow clients, removing white space can increase response times dramatically. You can also consider HTTP compression; however, HTTP compression affects CPU utilization.
You cannot always expect to design your pages in this way. Therefore, the most effective method for removing the white space is to use an Internet Server API (ISAPI) filter or an HttpModule object. An ISAPI filter is faster than an HttpModule; however, the ISAPI filter is more complex to develop and increases CPU utilization. "
Now I need to figure out how to write an ISAPI filter to remove white space.
7. Install Runtime Page Optimizer (RPO). Refer to http://www.iis.net/community/default.aspx?tabid=34&g=6&i=1716. There is a price to it.
Or Write your own optimizer. You can start by reading this blog http://www.darkside.co.za/archive/2008/03/03/web-page-optmisation-using-httpmodule.aspx.
Subscribe to:
Posts (Atom)