Friday, December 19, 2008

Textbox Multiline

When TextBos is in MultiLine Mode then its rendered as TextArea in html and TextArea doesn’t support MaxLength

Multiple Alter Column in a single T-SQL

multiple ALTER COLUMN clauses in a single DDL statement doesn’t exists in T-SQL Today.

Passing 2 ClientIds to a Javascript function

The best way to pass 2 ids is in C#
ClientID requires another id but this.id doesn’t require that

ModalpopupExtender focus

Modalpopupextender C# focus() doesn't work also javascript dynamic passing the id to focus is not working.

ModalpopuExtender displays in Page Load

I'd a ModalPopupExtender in a page which will be in invisible load but there was a problem. Every time page loads the nodalwindow appears for sometime and then disappears.
This can be soled by saying display: none in the aspx page

Replace Javascript Function

Javascript Replace replaces only the 1st occurance

The below is replaceall function
function replaceAll(subject, search, replacement) {
return subject.split(search).join(replacement);
}

Page_LoadComplete

Page_LoadComplete is a page event it will not work in Master Page and user control

Thursday, October 30, 2008

Retrieve Idenity

Lets say that you are inserting a row in a table which has an identity column.
You can retrieve the new identity using
Select @@IDENTITY

Pixel Character ratio

Lets say you want to fix the width of a textbox using pixel, this is the thumb rule.
70px = 10 char

Image Button using LinkButton

Isn't it cool to use just a linkbutton and some css stuff and make it look like an image button.


div class="btn_area">asp:LinkButton ID="LinkButton1" runat="server" CssClass="button" onclick="OkButton_Click">SEARCH /asp:LinkButton
/span
/div

Tuesday, July 29, 2008

Implementing Transactions in SSIS

Let’s say you’ve many control tasks and you’ve to implement transaction.
Points to Note:
1. You cannot Implement Transaction in a task which has truncation
2. Transaction has no effects in file processing and archiving it works only for DB

If you want to have transaction for only one task then select the Isolation Level as “Serializable” and TransactionOption as “Required”

If you want to have transactions for many or all of the control tasks then set the TransactionOption as “Required” in the package and “Supported” in the Control Tasks.
For the Control Task s where you doesn’t require transaction choose “Not Supported”

Vista Slow Copy to CD

I had some pictures in my ‘Picture’ folder and I copied and pasted it to the CD Drive and Vista was copying the files very slowly. At one point of time it showed “1222005 Days and 6 hours remaining”!!!!!!
I dono whether I can stay alive to see the files copied to the CD 
Every time it copies a file it showed a Try Again Dialog box.
I searched the net and found that this seemed to be an internal mapping issue.
The only way to get over this is to create a new folder in C Drive and copy the pictures there and from this folder copy to the CD Drive.

Tuesday, July 8, 2008

Its not = null It is "is null"

I'm doing this mistake time and again in T-SQL
You should not use = with null, you should always use is null
eg:
WRONG:
EndDate = null
RIGHT:
EndDate is null

Tuesday, June 10, 2008

The saga with CallServer

I have a long story to tell here.
It all started with me having to do some process when users close the browser.
So, I need a javascript to call server, we’ve a very easy way of doing this.
Follow the traditional way http://msdn.microsoft.com/en-us/library/ms178208.aspx
The below is the piece of code for implementing CallServer in Javascript:
******************************************************************

.
.
.
body onunload="DoUnload()"
******************************************************************
I tested it and it worked fine and I pushed the code in. After some time testers found a bug. The bug was when they closed the browser the required functionality was not getting implemented. In other words the server is not getting called when browser closes. Pls note that the above javasript is in master page.
So everything worked fine in my laptop but its not working in the server for some pages.
After a lot of debugging I found that it works if I’ve an alert message after callServer in servers.
But I’ve no idea why!!!!
After a lot of soul searching in the net I found that there is an issue with AJAX enabled page and the only way out is to open up a new web page using showModalWindow and have a page load event in the html page which should close in some secs!!
I showed this to the lead developer and he said that instead of opening up and showing a new web page, why can’t I minimize it.
So this is the code for mimimzing the web page and then closing it:
******************************************************************

function onLoad()
{
moveBy(2000,2000);
setTimeout('this.close()',0)
}
body onload="onLoad()"


******************************************************************
But there was another issue. The issue was showModalWindow opens the page as a Modal Window and we cannot resize the html page. So I changed from showModalWindow to window.open.
I implemented that but there was a big issue!!
The issue with directory structure!!!
The master page is in root directory and I created the close.html in the root directory, but we’ve a lot more pages in different folders and when you are in one of the pages in sub-folder and close the browser I get an error message. Why?, b’coz the html file is not there…. It is only present in the root directory.

So I wrote a code in javascript that solved the issue which I will share momentarily, but before that I had another issue!!!

The root paths are different for different server.
Its not a cool http://webserver/rootpath
It could be http://web/dir1/dir2/rootpath


I have the rootpath in web.config and I grabbed in Global.asax Application_Start event. Then I used it in the javascript.
Here is the Application_Start in Global.asax.cs
******************************************************************
protected void Application_Start(object sender, EventArgs e)
{
Application["RootPath"] = ConfigurationManager.AppSettings["RootPath"].ToString();
}

And here is the javascript:
**************************************************************

//***This function is called when the browser window is Closed
function DoUnload()
{
if (window.event.clientX < 0 && window.event.clientY < 0)
{
CallServer("2","unlock");
var url = window.location.href;
var rootpath = '<%=Application["RootPath"] %>';
var index = url.toUpperCase().indexOf(rootpath.toUpperCase(),0);
if(index == -1)
{
//For Local codebase
window.open("http://"+window.location.host+"/close.htm");
}
else
{
//For servers
index = index + rootpath.length;
//window.showModalDialog(url.substring(0,index)+"/close.htm");
window.open(url.substring(0,index)+"/close.htm");
}
}
}
******************************************************************


So I took a deep breadth and tested and found another bug
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

After doing a hell lot of research I found that the way to solve it is remove the javascript from the "head" and place it in the "body"

So I hope this ends the Saga.

Wednesday, May 7, 2008

IsNullOrEmpty

Never Never use if(x != string.Empty x != null)
use if(!string.IsNullOrEmpty(x))
it saves lots of time and space.

Friday, April 11, 2008

How to get the BuildNumber from TFS

I’ve spent close to a week figuring out how to do this.
I tried different options, the one which I spent a hell lot of time is to use $(BuildNumber). I thought I can create a custom Task using a C# dll which will grab the BuildNumber and update in web.config. I can easily display the info from web.config.
I don’t have rights to go in a TFS to run a build, so I was unable to progress much in this direction. Also we will never know whether we can update the web.config after its build and it’s a cumbersome process.

The next step then will be to somehow get the API to work in TFS.
In internet I was able to get some namespace but I was unable to locate these namespace in Reference under .NET.
I thought I was missing some APIs that I need to download but I had no idea where to go.
My colleague gave me a path to look at in my PC to get some TFS client dlls, I added them and got the namespace.
Once I got the namespace getting the methods to grab the BuildNumber was fairly easy.

Lemme explain the steps:
Grab the dll which is in C:\Program Files\Microsoft Visual Studio 8\Common7\ide\PrivateAssemblies as references look for dll starting with “Microsoft.TeamFoundation.<>”
Add Namespace
***************************
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Build.Proxy;
***************************
Here is the code to grab the BuildNumber
***************************
#region Get Build Number
TeamFoundationServer tfs = new TeamFoundationServer("");
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
BuildStore bs = (BuildStore)tfs.GetService(typeof(BuildStore));
BuildData[] bt = bs.GetListOfBuilds (, );
lblBuildNum.Text = bt[bt.GetUpperBound(0)].BuildNumber;
tfs.Dispose();
#endregion
***************************
URL: In Visual Studio File à Add Existing Team Project. In “Connect to Team Foundation Server” click on Servers. Here you can get the URL
Project Name: Type your Team Project, the list of Team Projects are displayed in the “Connect to Team Foundation Server”
Build Type: In Team Explorer expand Team Builds take any one of the Build Types mentioned there. (Don’t enter “All Build Types” it will not work)

ScriptManager in UserControl

I added a Script Manager in a user control and got the following error message: “Only one instance of a ScriptManager can be added to the page.”
The issue is the parent page (either the aspx page or master page) has a scriptmanager.
Now comes another part I added the UpdatePanel but I found out that when I wanted a partial refresh Page_Load event is getting fired!!
This could be b’coz the way this Control is called in the aspx page!!
Even if you do AJAX if the aspx calls the control in page load event we will not be able to help it out.
Bottomline: Think twice before adding AJAX in usercontrol.

Sunday, April 6, 2008

MSWord Uppercase - Lowercase

Highlight the passage and then press shift F3

Sunday, February 17, 2008

The Issue with Equals Method

We all know that Equals method is synonymous with ==
So we can say
a.b.c.equals(obj) instead of a.b.c == obj
But we may run across some issues here
Lets say there is a chance that a.b can be null
So we can write the code as
If(a.b != null && a.b.c.Equals(obj))
This looks alright but what if a.b.c is null!!
So we can say:
If(a.b != null && a.b.c != null && a.b.c.Equals(obj)
Wait…………..
There is another simple way to write this!
If(a.b != null && a.b.c == obj)
This works even if a.b.c is null
So this means use Equals method only when you’ve overridden the method, in all other cases we can be happy with ==

Friday, February 1, 2008

Developer’s Attitude on Developer Testing

During my initial days in software industry I was working in a level 3 support project. Initially I was doing less development and a lot of peer testing, b’coz this is a big application and the lead thought that the best way to understand the application is through testing. During the initial year I was one of the best testers. I had the energy and enthusiasm to test for corner cases. But after 4 years in development I really don’t have the patience to do even unit testing!
So what has gone wrong?
Is this the right attitude?
Do all S/W developers face this problem?
I don’t know the correct answer but for me I’m pretty happy with what I’m doing.
When you are into development you’ll have this mentality that whatever I’ve coded should be working correctly, but you should do unit testing but never should do regression testing.
Testers are present for doing just that and also to nail down some corner cases…..if you’re going to do the same thing that they will do then you are just wasting your time.When I started development I was coding for 1 day and testing for 3 days J
I was very cautious; I don’t want my bug to be reopened. So I was termed as a person who does things effectively but take some time to do it.
My lead was not unhappy, but I was draining my energy. I was wasting my energy on something which would’ve been definitely done by testers!!


So what am I going to gain by being over cautious?
Me being over-cautious affects both me and the tester.
I would’ve spent my time effectively in solving some other bug
If I covered all the scenarios and gave to tester, the tester will be running all the scenarios once again and would’ve got bored.

We should make the testers life interesting J
Let them find bugs and be happy about that……We will fix it when it comes.
A developer should not have ego. He should know that he can be defeated all the time and should not worry about that.
His aim is to code better and test it in the shortest possible time and give the rest of the job to tester.
Even Jon Bentley had a bug, why can’t you?

How does Contains work in Generic List

We all know what contains mean for string operation, but there is a little ambiguity on what contains mean in a generic list.
Does it look for the correct item or does it look for all the Items which contains the entry.
Even though I know the answer intuitively I just thought lemme confirm that with a simple program.
The Program is as follows:
***************************************************************************************************
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main (string[] args)
{
List intList = new List();
intList.Add(100);
intList.Add(11);
intList.Add(111);
if(intList.Contains(1))
Console.WriteLine("one is present");
if(intList.Contains(11))
Console.WriteLine("11 is present");
if(intList.Contains(100))
Console.WriteLine("100 is present");
}
}
}
***************************************************************************************************
The output is :
11 is present
100 is present

So it looks for the *exact* Item

Thursday, January 10, 2008

Factory Setting for Vostro 1500

A month ago the drivers in my Laptop got corrupted and I’ve to call the dell helpdesk.
The call lasted for more than 2 hours (I was literally crying inside b’coz I’d a pre-paid mobile) and I was routed to 3 divisions of the call center.
Finally it was decided that the only way out is to install Factory Settings in my Laptop.
The steps are as follows:
1. Restart the machine
2. When the Machine gets booted press F8 repeatedly
3. The Screen will show many options one of them is Install Factory Settings.

DefaultButton

In a given page we can have both a Form DefaultButton and also Panel DefaultButton.
A Panel’s DefaultButton takes high priority then the Form in that panel level.
We can’ve DefaultButton for the Form in both the Master and in the Page.
So naturally the Page’s Default Button gets precedence.
What if we’ve decided to have only Panel DefaultButton in a page but the page gets inherited from
A Master Page which has a Form DefaultButton?
Override the Master’s DefaultButton by setting the Page’s default button as null
*********************************************************************
Page.Form.DefaultButton = null;
*********************************************************************

Tuesday, January 8, 2008

Application_Error File not Found

I had an Application_Error in every page and the Server.GetLastError() was file not found.
The issue is I was unable to trace which file was not found. I even looked into Event Viewer but dint get any clue.
I googled and after a couple of hours got a solution from one of the forums.

The answer is when you do a debug and have the break point in Application_Error in Global.asax.cs now maximize the IE window of the application and see the status bar. It should show the file which the application was trying to retrieve. This is the file which was not found