Thursday, August 2, 2007

Efficient .ASPX pages

A comprehensive checklist would be great. Slowing tickets could be assigned to violators and we could better arrive and agree on guidelines; otherwise, what is known may still be ignored or forgotten.

So its worth mentioning the following (and more):

- Turn ViewState off on page and control levels when not needed
- Turn SessionState off:
"Session objects consume valuable resources. By turning off sessions, you can improve the performance and scalability of your ASP Web application. You can turn off session state either for the whole Web site or for specific ASP pages."

http://support.microsoft.com/kb/244465

- Alternatives to server controls include simple rendering, HTML elements, inline Response.Write calls, and raw inline angle brackets (<% %>).

(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)

- Especially if not compressing html:
Remove or reduce white space. Removing white spaces can dramatically reduce the size of your pages. Less white space did have about a 5-10K impact on move.com home page when viewed on the browser File-Properties.


-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.

- Use Output caching for user controls , pages, etc. (%@OutputCache directive
)


- Use static properties instead of the Application object to store application state.
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)

- Consider html size and preformance differences such as:
a label with onclick vs an href onclick
a Literal vs a label's final html



-Use Page.IsPostBack to Minimize Redundant Processing
- Use client side validation to avoid unecessary server hits

-Avoid Creating Deep Hierarchies of Controls (see http://msdn2.microsoft.com/en-us/library/ms998549.aspx#scalenetchapt06_topic11)




http://msdn2.microsoft.com/en-us/library/ms998596.aspx

Friday, May 4, 2007

Reading a .csv or a comma-delimited .txt file using SQL

Sample code for Reading a .csv or a comma-delimited .txt file using SQL:

Below:
1) StoragePath is the absolute path to the .csv file.
2) Substitute MyFileName.csv with your file name.

using System.Data.Odbc;
public void ReadData()
{
string StoragePath = @"c:\test";
string strSQL = "Select * from MyFileName.csv";
OdbcConnection conn = new OdbcConnection(
@"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ="+StoragePath);


conn.Open();

OdbcDataAdapter da = new OdbcDataAdapter(strSQL, conn);

DataSet ds = new DataSet();

da.Fill(ds);

conn.Close();
}

Sunday, April 29, 2007

Class does not support automation

Javascript: "Class does not support automation". Occurs when opening a popup.


Solution:

http://www.anetforums.com/posts.aspx?ThreadIndex=8917

regsvr32 Shdocvw.dll
regsvr32 Shell32.dll
regsvr32 Oleaut32.dll
regsvr32 Actxprxy.dll
regsvr32 Mshtml.dll
regsvr32 Urlmon.dll