______________________________________________________________________ Tip of the Day! Guidelines For Rendering Grid Data · Avoid using inline code. · Avoid using Response.Write from the Page_Load event in the code-behind class. · Do not use the concatenation operators when building strings iteratively. Always use the StringBuilder class. · Avoid using server-side table objects when building tables with large numbers of rows. · Avoid using the Repeater control for building grids. · If you use the Repeater Control, use the DataBinder.Eval method to extract values from the DataSource. ______________________________________________________________________ Tip of the Day! Guidelines For DataReaders · Don't use CommandBehavior.SequentialAccess with the ExecuteReader method unless you are accessing a large amount of blob data in each row. · Don't bother trying to use the specific typed accessor methods or a DataReader if you are building up a string. Only use them when you need to interact with the data in the native type. ______________________________________________________________________ Tip of the Day! Guidelines For Creating Controls · If you have time during development or you need to share a control across multiple projects, create a custom control. This will give perform on a par with running code directly in the web form code-behind. · If you need to rapidly create a grid control that will be used only within a single project then create a User Control. · Don't create generic classes that return large strings. ______________________________________________________________________ Tip of the Day! Code Location Guidelines · Always place page logic within the code behind class, not within script blocks in the HTML portion of the page. · Use Classes to encapsulate business logic only when that logic must be shared across more than one page. ______________________________________________________________________ Tip of the Day! Guidelines for Releasing Always set the debug attribute of the compilation element in the web.config file to "false" before releasing an application to production. ______________________________________________________________________ Tip of the Day! Guidelines for Option Strict If you don't mind being nagged by the compiler at design-time to explicitly cast your variable assignments, then set Option Strict to On to gain a small performance boost and help your code avoid unforeseen errors. ______________________________________________________________________ Tip of the Day! Guidelines for Session State · For a small performance gain, disable the Session State at either the page or application level. · Definitely disable page level Session State for pages not requiring the Session when using an external Session resource, such as SQL Server. ______________________________________________________________________ Tip of the Day! Do not access user controls programmatically with a cache directive Do not access user controls programmatically with a cache directive. If the control is found in the cache, the runtime will not instantiate the user control, so you won't be able to access it and an exception will be generated. ______________________________________________________________________ Tip of the Day! Use fragment caching to speed up the common elements in your application Use fragment caching to speed up the common elements in your application, such as menus and navigation bars, by creating user controls and caching those. VaryByControl will vary the cache based on the value of the web server controls in the user control. ______________________________________________________________________ Tip of the Day! You can cache the response for a Web Form request You can cache the response for a Web Form request. Be careful when using the VaryByParam attribute if there are a lot of parameters with a lot of options, as you could end up caching far too much. You can also use VaryByCustom when you want to vary the cache based on something that isn't a parameter. ______________________________________________________________________ Tip of the Day! Cache anything that won't change too often Cache where possible anything that won't change too often, and which otherwise you would have to keep reading from disk. ______________________________________________________________________ Tip of the Day! Use weak references when you have an object that you'd like to keep, but that you don't mind if the garbage collector decides it needs the memory for something else Use weak references whenever you have an object that you'd like to keep around as long as you can, but that you don't mind if the garbage collector decides it needs the memory for something else. This way you don't have to keep it open at the expense of other functionality, nor do you have to explicitly throw it away and create a new one every so often. ______________________________________________________________________ Tip of the Day! Use Jagged Arrays Jagged arrays provide savings in memory and performance over multidimensional arrays. ______________________________________________________________________ Tip of the Day! Use exceptions wisely Use exceptions wisely. Exception handling is cheap, but actual exceptions come at a cost. Only throw exceptions if the situation is actually exceptional. In other situations, consider alternative methods of handling the situation. ______________________________________________________________________ Tip of the Day! Expose an object's data fields as properties Exposing an object's data fields as properties lets us delay computation until the information is really needed. ______________________________________________________________________ Tip of the Day! Using VBScript to check whether Acrobat Reader is installed on a client's system This tip uses VBScript to check whether Acrobat Reader is installed on a client's system or not: ______________________________________________________________________ Tip of the Day! Authentication for Intranets Forms based authentication is an independent authentication method that works equally well for local and remote users of anintranet, since login information is requested from the user as part of the web application. Windows integrated authentication involves tying intranet authentication in with existing network accounts. This is great for local network intranets, since users only need to log on once, when they log on to their Windows domain account. The account information is then passed on to the intranet code when they access the site, so that they don't need to enter additional information. This has the effect of streamlining things, and makes the intranet feel more like a corporate application. The main benefit is that all user account information is centralized. ______________________________________________________________________ Tip of the Day! IBuySpy Portal Downloads There are four different versions of the download for IBuySpy Portal, two for the VB.NET version of the code and two for the C# version. The difference between the two versions is that one of them (the VS.NET version) is intended for Visual Studio .NET users while the other (the SDK version) isn't. There is no difference in functionality between these versions, only that the VS.NET version uses the "code-behind" model for all ASP.NET files, where the code is contained in separate files rather than being included in .aspx and .ascx files, and includes solution files for loading straight into the VS.NET IDE. ______________________________________________________________________ Tip of the Day! Identify common tasks and package them into re-usable components Identifying common tasks and packaging them into re-usable components at the early stage of an intranet implementation is very important to cut the implementation time and improve manageability. ______________________________________________________________________ Tip of the Day! GDI+ GDI+ derives its name from its predecessor, the Graphics Device Interface or GDI that allows you to display graphical output on the screen, printer, or on a bitmap in a memory too. GDI+ as a set of classes (gdiplus.dll) written in C++ is a subsystem of the Microsoft Windows XP and Windows .NET Server operating systems and can be used both in managed and unmanaged code. ______________________________________________________________________ Tip of the Day! Don't store more session state information than you need Don't store more session state information than you need; excessive use of state storage can impact scalability. Today’s tip is taken from Professional ASP.NET Performance (http://www.wrox.com/books/1861007558.htm) ______________________________________________________________________ Tip of the Day! Minimize the number of server-side controls Minimize the number of server-side controls. Server controls use not only view state, but also have their own associated processing costs. Today’s tip is taken from Professional ASP.NET Performance (http://www.wrox.com/books/1861007558.htm) ______________________________________________________________________ Tip of the Day! Turn off view state Turn off view state for controls that you don't need persisted during a postback. Turn view state on for entire pages if they will never be used to post back. ______________________________________________________________________ Tip of the Day! Remove the guest user account from IBuySpy The guest user account included with IBuySpy has the password 'guest' and is part of the Admins role, thereby having the highest level of security permissions. Given the generic nature of this account, it should be eliminated to prevent unauthorized access to the portal. If you still want to have a guest account for your portal, you should at least remove it from the Admins role, and assign it minimum permissions required to access the desired resources in the portal. Removing or altering the guest account is one of the first things that should be done after installing an IBuySpy application. Leaving it in place leaves a huge security hole. Today’s tip is taken from Building an ASP.NET Intranet http://www.wrox.com/books/1861007493.htm) ______________________________________________________________________ Tip of the Day! Using Enterprise Manager with MSDE If you only have MSDE installed then many administration tasks may only be carried out using command line SQL queries. Here's a tip: get the Enterprise Manager application from the MSDN SQL Server evaluation download - it'll make your life a lot easier and isn't limited by the 120 day trial license that applies to the SQL Server database download itself! ______________________________________________________________________ Tip of the Day! Context Switch The process of shifting between threads is known as a "context switch". A context switch occurs when the details and "state" of the old thread is swapped for the new thread (which will have a small proportion of the processors time). ______________________________________________________________________ Tip of the Day! JIT and gc optimization The JIT compiler and garbage collector perform a number of optimizations, which means that you don't have to. Trying to out-think the framework will rarely result in any performance gain. ______________________________________________________________________ Tip of the Day! Be wary of doing too much performance tracking It should be remembered that the more in-depth the tracking of performance, the more that the performance is altered by performing such tracking. ______________________________________________________________________ Tip of the Day! Don’t prefix the name of your stored procedures with sp_ System stored procedures in SQL Server begin with sp_. If your stored procedures also begin with the same three letters as the system defined ones, then rather than being found in the portion of the database allocated to user-defined procedures, and executed immediately, the system will first look through all of the system defined ones to see if it exists. This will cause a minor slowdown, but as it is done on every single table there is no need to suffer this overhead for the sake of a slight modification to naming conventions. As a further benefit, using a different naming convention will also help developers distinguish between custom functionality for the application being developed, and standard functionality provided by the underlying system. ______________________________________________________________________ Tip of the Day! Performance counters only retain data for as long as there is a reference to the counter Performance counters do not store performance data like an event log, or an entry in a database. A performance counter will only retain data for as long as there is a reference to the counter. When the last reference to a counter ends, the counter is reset to 0. While we can use logging and trend analysis to get a good idea of performance over a period of time, a performance counter is designed to record only while active. ______________________________________________________________________ Tip of the Day! Enabling smart navigation for an entire web site You can enable smart navigation for an entire web site by using the 'smartNavigation' property of the "pages" setting in the web site’s web.config file. You can also specify it as the default for all web sites on a particular machine by setting the same value in the machine.config settings file: ______________________________________________________________________ Tip of the Day! Smart Navigation Smart Navigation is a seldom-documented feature of ASP.NET and was introduced to solve the annoying problem of refreshing every control and losing the current control’s focus that you get when refreshing a page. To enable smart navigation for a page, you enable the smartNavigation property of the @Page directive: <%@Page Language="vb" AutoEventWireup="true" codebehind="WebForm1.aspx.vb" Inherits="WebForm1" smartNavigation="true"%> ______________________________________________________________________ Tip of the Day! Performance Caveat When optimizing an application for performance, it is important to also consider business rules, maintenance aspects and functionality. Performance is not necessarily the be-all and end-all so might not be the overriding factor in your decision-making. ______________________________________________________________________ Tip of the Day! Minimizing web server load The following tips will help in minimizing web server load: * Optimize Windows 2000 for background processes (under Control Panel | System | Advanced | Performance) * Optimize IIS for >100,000 hits per day (under Internet Services Manager | Properties | Performance). ______________________________________________________________________ Tip of the Day! Minimizing database server load * Use stored procedures to ensure that the SQL statement is precompiled * Select only a small number of columns in your SELECT statements to avoid delays caused by any migrated rows * Make sure that at least one of these columns is indexed to enable faster retrieval ______________________________________________________________________ Tip of the Day! Application Level Tracing If you plan on taking advantage of application level tracing (trace.axd) in the production environment, you have to remove the Page directive’s Trace attribute from all the pages. Leaving the Trace attribute in the Page directive will invalidate application level tracing for that page. ______________________________________________________________________ Tip of the Day! Retrieving the Server Name in ASP.NET Applications Occasionally, during socket programming, we need the name of the server running the script. In Microsoft.NET, there are many ways to get the name of the server. Depending upon the context, such as whether we are in a WebForm or in a Component, we can suitably use a particular method to get the name of the server. The following small example illustrates the different options: protected void Page_Load(object sender, System.EventArgs e) { Response.Write (System.Environment.MachineName+"
"); //System.Environment Class Response.Write (Server.MachineName+"
"); //HttpServerUtility class Response.Write (System.Net.Dns.GetHostName()+"
"); //System.Net.Dns Class } ______________________________________________________________________ Tip of the Day! New Improved Image Swap On 5th November we published an image swapping tip. ASPToday reader Krishna Tummala has supplied a more elegant solution (that is a third the size) that has the same functionality:

John or Appleman?

______________________________________________________________________ Tip of the Day! Formatting a number using FormatNumber Use FormatNumber to format a number with the commas in the appropriate places and a predetermined number of digits after the decimal. This is really useful for financial web application where you have large numbers as they can be difficult to read on an html page. <% Dim mynum Mynum = 111222333.5 Response.Write(FormatNumber(mynum,2) %> The result would be: 111,222,333.50 The 2 stipulates the number of digits after the decimal point ______________________________________________________________________ Tip of the Day! Tracing places a large overhead on the server Application level tracing is retained in memory so you don’t want to set the requestLimit to a ridiculous amount and run your server out of memory. ______________________________________________________________________ Tip of the Day! Determining which version of the .NET Framework you have installed Microsoft Knowledge Base Article 318785 (http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318785) shows you how to determine which version of the .NET Framework you have installed. The version numbers are as follows: Version 1.0 = 0 (1.0.3705.0) SP1 Revision = 209 (1.0.3705.209) SP2 Revision = 288 (1.0.3705.288) ______________________________________________________________________ Tip of the Day! What version of SQL Server am I running? You can find out what version of SQL Server you are using, and which service packs you have installed by running: Select @@version from SQL Query Analyzer. ______________________________________________________________________ Tip of the Day! Mapping An Image The following code shows a way of mapping an image. If you click on part of Appleman's image, the text box below will give a description of that part. For example, if you click on the hat, the text box will display "Hat". Point and Name

______________________________________________________________________ Tip of the Day! Is JavaScript Enabled? The following snippet determines whether you have JavaScript enabled on your browser: <%Dim thisBrowser set thisBrowser = Server.CreateObject("MSWC.BrowserType") Response.Write thisbrowser.javascript%> ______________________________________________________________________ Tip of the Day! JavaScript ASCII Code Generator The following JavaScript will display the ASCII code for the entered character in an alert window. For example, the ASCII code for £ is 163.
Type a character:
______________________________________________________________________ Tip of the Day! Using JavaScript to redirect to a different URL after a time delay If you can't use the "http-equiv refresh" tag we showed you yesterday, you can use the following JavaScript to automatically redirect visitors to your site to a different URL. In this example, the page will redirect the user in 5 seconds. Redirect using JavaScript
You will be automatically redirected to ASPToday in 5 seconds. Please bookmark the correct page at http://www.asptoday.com ______________________________________________________________________ Tip of the Day! Add A Delay Before Redirecting If you need to automatically redirect visitors to your site to a different URL, you can use the meta tag "http-equiv refresh". In this example, the page will redirect the user in 5 seconds. Meta tag refresh delay
You will be automatically redirected to ASPToday in 5 seconds. Please bookmark the correct page at http://www.asptoday.com
______________________________________________________________________ Tip of the Day! Strong Data Types With ADO.NET, if a column in a database is an integer, you retrieve, store and work with it as an integer - saving time, as you don't have to do any data conversion. ______________________________________________________________________ Tip of the Day! More Microsoft Naming Guidelines Do not use class names that overlap with namespaces (sush as System, UI etc.) Do not use the underscore character. Do not use identifier names that conflict with keywords. Do not use abbreviations in your identifiers. Acronyms in identifiers should be treated as a word, not all uppercase (SqlClient not SQLClient) Use nouns and noun phrases when naming classes and namespaces. Verbs should be only used for method names. ______________________________________________________________________ Tip of the Day! Microsoft's Naming Guidelines Microsoft strongly recommends the use of Pascal casing - where all words in an identifier have their first letters capitalized and there is no separation character between words. Another type of capitalization scheme is camel casing - where the frst letter of the identifier is lowercase, but subsequent words have their first letter capitalized. PascalCase is used for classes, Enum values, Enum types, Events, Exception classes, interfaces, methods, Namespaces and properties. camelCase is used for parameters and private member variables. ______________________________________________________________________