Tuesday, December 29, 2009

what colors to use for your web design

A nice article for programmers like me who are always confused about what colors to use:

http://articles.sitepoint.com/article/color-for-coders

Another one for web site design:

http://articles.sitepoint.com/article/principles-beautiful-web-design/2

Monday, December 28, 2009

For Share Point Development

Just saw this one. Its a great list of things you need to be a Share Point Developer.

http://blogs.msdn.com/pandrew/archive/2008/05/01/getting-started-with-sharepoint-development.aspx

Wednesday, November 18, 2009

log4net or logging application block

some information here at:
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=10534

pros and cons:
http://weblogs.asp.net/lorenh/archive/2005/02/18/376191.aspx

a thread:
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=11300

Thursday, November 12, 2009

IIS on XP allowing upto 40 connection

Here is a blog that describes the issue:

http://weblogs.asp.net/cazzu/archive/2003/10/10/31476.aspx

Following command is described in it to set max upto 40:

adsutil set w3svc/MaxConnections 40

Friday, October 16, 2009

How to get Browser height width on server side using ASP.Net Page Methods

You need to know how the ASP.Net Page methods work for this one. You may get some idea from this post as well.

I am not very good at manipulating CSS and Javascript to find out current browser height/width and set the control height/width accordingly so that the page looks right in all types of browsers. Hence I needed to get the Browser Height/Width on the server side and then use the appropriate CSS file to show page correctly.

1st - create Javascript functions to get the height/width:


function getBrowserWidth() {
if (window.innerWidth) {
return window.innerWidth;
}
else if (document.documentElement && document.documentElement.clientWidth != 0) {
return document.documentElement.clientWidth;
}
else if (document.body) {
return document.body.clientWidth;
}
return 0;
}
function getBrowserHeight() {
if (window.innerHeight) {
return window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight != 0) {
return document.documentElement.clientHeight;
}
else if (document.body) {
return document.body.clientHeight;
}
return 0;
}


2nd - create a WebMethod in your code behind. I have put this method in my base page so I can use it from any aspx page.


[WebMethod]
public static void SetResolution(int width, int height)
{
if (width <= 1024) width = 1024;
if (height <= 768) height = 768;
SiteSession.Current.BrowserWidth = width; //Session["BrowserWidth"] = width;
SiteSession.Current.BrowserHeight = height; //Session["BrowserHeight"] = height;
}//SetResolution

3rd - now the goal is to call this page method at the time of login or at the time when page resizes


PageMethods.SetResolution(getBrowserWidth(), getBrowserHeight(), voidFn, voidFn);

you can also create a function call it as:
window.resize = function () { PageMethods.SetResolution(getBrowserWidth(), getBrowserHeight(), voidFn, voidFn); }

Now, whenever the page loads and resizes, the browser height width will be stored into Session. You can use that while rendering next/other pages:

4th - in your master page for all pages create a Header as below:

<head id="Head1" runat="server">
</head>

And then add appropriate css file:


protected override void OnPreRender(EventArgs e)
{
HtmlLink myHtmlLink = new HtmlLink();
myHtmlLink.Href = string.Format("~/css/{0}", GetResFileName());
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");
// Add the HtmlLink to the Head section of the page.
Head1.Controls.Add(myHtmlLink);
}


public string GetResFileName()
{
string fileName = "1280x1024.css";
if (SiteSession.Current.BrowserHeight < 800)
fileName = "1024x768.css";
return fileName;
}

Happy Diwali

Here is President Obama wishing everyone Happy Diwali.

http://www.youtube.com/watch?v=SuiAW_6XKVM&feature=popular

He notes return of "Ram" that means he is more open than our psuedo-secular indian media and the leftists.

Friday, October 2, 2009




Today Google's Logo is Gandhi for G. Great! and Thank you Google.

Thursday, October 1, 2009

How to use Session in ASP.Net

The traditional way of using Session in ASP.Net/C#/VB.Net has been to use Session["variablename"].

Disadvantages of using Session this ways is:
* You could have typo in the variable name and can get errors that takes time to figure out the reason.
* Session["x"] will return an object that you would have to convert to the type that you need
* You never know what are all the session variables used in the application and what is the size of session at any given time
* There is no intellisense to tell you if a Session variable already exists
* Different developers may use different names to store the same information in session

A better approach of using Session is to create a (semi)singleton class as following.

public class SiteSession
{
private object _lock = new object();

//do not allow creating new objects of this
private SiteSession()
{ ; }

public static SiteSession Current
{
get
{
if(HttpContext.Current.Session["SiteSession"] == null)
{
lock(_lock)
{
if(HttpContext.Current.Session["SiteSession"] == null)
HttpContext.Current.Session["SiteSession"] = new SiteSession();
}
}
return (HttpContext.Current.Session["SiteSession"] as SiteSession);
}
}

public string SessionVar1 { get; set; }
public int SessionVar2 { get; set;}
}

public class BasePage : System.UI.Web.Page
{
public SiteSession MySession { get { return SiteSession.Current; } }
}

Now, whenever you use SiteSession.Current or MySession in the pages, you will see the intellisense for your session variable. This now helps keep all session variables at one spot.
Also there is no typo any more. You don't have do the type conversion anymore.

You can also create a base-class for your user controls and add MySession property to that user control. So, you will be able to access the session variables easily from your user control as well.

In your static/page methods/web methods, you can use SiteSession.Current to access the session variables.

Wednesday, September 30, 2009

Use Telerik - It's worth it; Not Infragistics

In Nov/Dec 2007, one of my client asked us to use Telerik controls. At first, I was skeptic and did not want to introduce one more new thing in the project. It was our first 2005, .net 2.0, Ajax project. (I am running behind others in technology ain't i?). Till then we had used 2003, .net 1.1 and very little Ajax.

So, I ignored and when the saw first prototype with all .net native controls, they were so furious (obviously) because none of us were great graphics designers. And it was very poor looking application then.

And I thought let me have a look at Telerik. Woila, it had everything I "did not want to do". (this is positive sentense). I did not want to create stylesheet myself and check how different colors look for a table or button or drop down blah..blah... I did not want to write javascript to add some dynamic value to drop down... did not want to design javascript menus.... and Telerik did everything.

The best part was their Client object Model. They provide very rich set of Javascript classes for the controls that you are using that Javascript becomes fun to program. Javascript was my limitation - and they fulfilled it. Not that I don't know, but I don't like to write big javascript code. Even Firefox's FireBug helped debug the javascript.

In 2008 I got to see Infragistics being used in a project. It was Windows Smart Client project. Now, Infragistics had lots of properties for everything. And all those property names were not intuitive. Like in .net controls you may have some property Visible=true/false. Infragistics won't have that property but instead a method Hide() or Show(). Shortcomings of Infragistics was not in terms of features but more in terms of the usability. We were using Office Green theme for Grids, but everytime we go to set theme, it would reset it.

Then I checked to see if we can use it for Web development. But unfortunately their Javascript object model is not as strong as Telerik's ones. For example, to add a TAB to a TABSTRIP, you can use Javascript in Telerik controls, but Infragistic only does this from Server side. This is a true shortcoming.

The Help documents of Infragistics is very poor; while Telerik help is really helpful.

I finally bought Telerik controls in early 2009 and using it for my clients. They actually like the UI that I create using Telerik.

I am not really paid by Telerik to write this post. This is just my honest opinion.

I hate NetTiers

If Eric Smith reads this, he certainly is not going to like the title. But over the time, the way NetTiers has been used in our project, the team has got so frustrated that I am using the strong "h" word. But I believe the fault is never of the tool but the way tool is used.



I love CodeSmith in true sense. I have used CodeSmith since 2005 when I first found out about it and have always proposed using it wherever I have worked so far. I myself own CodeSmith and have made three other people to buy and use it.



In 2008, I volunteered to join a project that was going through tough times - and one reason I wanted to join was because they were making use of CodeSmith and I thought I can definitely contribute. After joining I came to know that its not 'CodeSmith' that they use, they use 'NetTiers'. You will ask, what's the difference? But there is.


Somewhere in the early phase of the project, someone brought NetTiers to the table mainly for the reason of supporting both WebService and direct access w/o much coding. I believe primary reason of using any tool should not be just avoidance of some work. Because I believe the amount work balances out for the whole life cycle of the project - one or the other way. After introducing NetTiers, following problems started occuring:

* Every developer did not have Code Smith license. And honestly, companies won't buy it for everyone. They had one guy doing the NetTiers generation everytime. Now, he became the bottleneck.

* All developers started depending on the NetTiers generation everytime even a small database change was made. Even if a field is added, they would request NetTiers generation, and until it is done they would have to wait.

* The NetTiers generation caused updating all layers (bussiness objects, data access, comp. layer-services) for all the database objects. So, database changes done by other developers would also creep into main code while their relevant code changes in other layers were not committed. This requires then error fixing, code merge, exclude some source files etc.

* Developers started making temporary database calls right from their presentation layer to avoid waiting for NetTiers and then would forget that some code is not using NetTiers and in turn would fail with web-services.

* Now the real issue: Web-services in NetTiers is over the stored-procedure calls. they are not true business services. So, maintaining transaction over the web-services was next to impossible. I am still surprised why the architect/team leads could not see this on day one? Besides, what good is a call to Stored Procedure via web-service? This kind of feature just misleads people.

* Developers called GetAll().Find() type of method only to make the application slower. They never understood the drawback and noone told them either.

* To Update 100 records, you would have to create 100 objects and XML of those objects is passed over the web-service. Developer were not careful about this fact either.

* The small changes to database like varchar(50) to varchar(100) would also make application fail with some validation errors. And it requires to regenerate the NetTiers.

Most of above issues, as you see are because of lack of understanding by the development team; The facts that I disliked the most was - being dependent on the NetTiers regeneration for any changes. I would like some freedom in a way that if I made some change to db, I would go to specific code/stored procedure and make relevant change. But NetTiers generates so many layers of code that there myriad number of places that one would have to change.

NetTiers may be good for very small systems, or admin applications that one or two people are working on. But you don't want to use it for large systems with bigger teams. Anyhow the budget of large systems and bigger teams would justify having custom business objects/data access layer.

At the same time, I would definitely create Custom templates and use Code Smith to generate the DEO/DTO (Data Entity/Transfer objects) and DAO (Data Access Objects), stored procedures etc.

I surely love CodeSmith for that purpose.