Thursday, December 25, 2008

Jquery for Beginners: Events Handling Part 2

This is the second article of the Jquey for Beginners: Event Handling. In the first Article i give some information how you attach the event with the controls. Here is the list of the some of the event helper Table 1.

Event NameEvent Name
error() error(fn)
mousedown(fn) mousemove(fn)
hover(handlerIn, handlerOut)toggle(handlerEven, handlerOdd)
These are the event handler used in the jquery and also called Event helper. The events i have mentioned above in the table return jquery object by which the event is bind, as jquery support chainability so the return object is used to apply another function on that object. We can divide events in the Table 2 into three categories.
  1. Events which are related to the mouse, also called mouse events which include click, mouseover , mouseout etc.
  2. Events which are related to the key board, also called Keyboard event which include the keypress, keyup etc.
  3. Events which are related to the form. which include the load and unload of the form.
Let us start with the events related to the mouse, then event related with the keyboard and the at the end the events which are related with the form.
The event listed in Table 1 are also the shorthand of the bind() event handler where you have to specify the event name and the function to be executed when the event is fired. Let us start with the most used mouse event which is click. Here is the code you can use to bind the click event with the control.
// use this to reset a single form
alert("Button is Click")
The code above is simple one i have used the id of the button "reset" to bind the click event with it, so when the button is click alert message "Button is Click" is shown. Below is the code for both the click(fn) and click event handler. The code above is also shortcut for the .bind('click', handler)


function ClickCalled()

you can see the from above code snip that when the page is loaded the function is called as i have call the $("#myDiv").click(); which will call the function associated with the click event or you can say in the previouse statement i have attach the ClickCalled function. This remind me the buttonName.PerformClick(); function. Which i love to use in the desktop application when i develope the desktop application, now i am happy to use it in the jquery as well and i am very happy that jquery has given this functinality.Although we can call the function but calling the click() function is really cool. Remember that you have to attach the click event handler before
calling the . click() event. The dbclick event is similar to the .click except the event is fired when mouse is double click and hope you can do yourself i will not explain it here, if you need help regarding dbclick then please tell me i will help you.
Next event which i will explain you related to the mouse is the hover() event handler , you can see in Table 1 that the .hover(handlerIn, handlerOut) takes two functions as parameter one is used when mouse enter into the control to which the hover is bind and the handlerOut is used when the mouse is leave that control. For the javascript programmer who use the mouseout and mouseover for the simple effect for example when mouse is over to over a button then the background color is change from the default to new color and when mouse is out of that control then the default color is set.

Above is the simple code which illustrate how you can use the hover event handler to bind the two functions, the above code will change the background color of the div which to pink when the mouse is over the div and set the default color of black when mouse leave the div control.

The remain events which are related to the mouse , i will leave the reader to discover them and use them, if you need any help regarding the the mouse events please do tell l me. Events for the keyboard and the form i will discuss in next post , hope this will help you and you get some help from this post as well. If you have any question please do tell me , i will try my level best to give you answer.

back to content

How to Get Selected Value From DropDownList Using Javascript

In this post i will tell you how can you get the selected value of the DropDownList of control using javascript. It is simple code but i think this will help you. Below is the sample code you can use in your cod.

function getSelectedItem(dropDownList)
//get the selected index of the dropDownList
var intSelectedIndex = dropDownList.selectedIndex;
//check if there is selected item or not
if(intSelectedIndex != -1)
//get the value of the dropDownList
var value=dropDownList.options[intSelectedIndex].value;
//get the text of the dropDownList
var strText= dropDownList.options[intSelectedIndex].text;
what ever you like to with the value and the text as you
get these properties of the dropDownList

In the above code i have use function getSelectedItem which take dropDownList control object as parameter. In the first statement of the function i have get the selectedIndex of the dropDownList and store it in the variable intSelectedIndex . In the next line i have use the if condition to check whether selectedIndex is not equal to the -1 which indicate nothing is is selected. If selectedIndex is not equal to the -1 then it mean user have selected some value in the dropDownList, In the if condition block i have used that selectedIndex to get the value and the text of the dropDownList item. I have store the value and text in seperate variable so that you can use it whatever your need is. Hope this will help you and if you have any question please do ask me.
Happy programming :)

Wednesday, December 24, 2008

DropDownList Add/Remove Item Using Javascript

In this post i will discuss operations such as insert/Add and remove item from DropDownList using javascript. I have used insert and remove operation to add and remove items from dropdownlist using javascript in my projects very often. And i think it is good to share my knowledge regarding this operation with you people as well. First i will discuss how you can remove all the items from the dropdownlist and then how you can add item in the dropdownlist using javascript.

Removing Items from DropDownList

Below is the simple code to remove the items from the dropDownList. In the code below i have created a simple function name clearDropwDownList , the function will take the dropDownList control object as parameter.

function clearDropDownList(dropDownList)
//get the total item from the dropDownList
var intTotalItems= dropDownList.options.length;
//loop through the number of items
for(var intCounter=intTotalItems;intCounter>=0;intCounter--)
//remove the intCounter( currently index) item from the dropDownList

At the first line of the function i have declared variable named intTotalItems which will hold the number of items in the dropDownList which is passed to the function. Then i use the for loop to remove the each item in the dropDownList by using the remove(intCounter), statement where intCounter is the current index to be removed.

Add Items from DropDownList

Now how to add new value(s) in the dropDownList, below is the code you can use to add the value to the dropDownList, i have created function for this operation as well, so you need to pass the dropDownList control object , the value field and the text field to be added in the dropDownList as new item.

function addDropDownListItem(dropDownList,value,Text)
//Create new item option to be added in the dropDownList
var newOption = document.createElement("option");
//assign Text value to the text property of the option object
newOption.text = Text;
//assign value to the value property of the option object
newOption.value = value;
//add new option in the dropDownList

First i have created the option object to hold the text and the value of the new item and then i assign the values to the text and the value property and at the end added the new option in the dropDownList.

If you have any question regarding this post please ask me

Happy programming :)

Saturday, December 20, 2008

Jquery Content

These are the series of articles regard the jquery for the beginners series if you have any question please feel free to ask any question regarding my post. Here is the list of articles you can find in this series and this will updated regularly as i post new article.
  1. Jquery for Beginners
  2. Jquery for Beginners:Events Handling Part 1
  3. Jquery for Beginners:Events Handling Part 2
  4. Jquery for Beginners: Events Handling Part 2 ( continue)

hope you will like this series, if you like that i will write article of your choice regarding in this beginner series , please do tell me i will try to to add that article in my series.

Friday, December 19, 2008

Jquery for Beginners: Events Handling Part 1

This is the second article of the Jquey for Beginners. In the first Article i give some information how you can get started with the jquery. In the second article i will give starting point how you can bind the events with your control in order to do some actions against user interaction with the web application. If you see the jquery documentation for the events , documentation categorize the events into four types 1) Page Load, 2) Event Handling also called event attachers, 3) Interaction Helpers and 4) Event Helper. In first article, we noted that $(document).ready() is the jquery way to perform the action which are need to in page load and this function is similar to the javascript function onload. So if you want to read more about ready() handler please read my first article. Here are the ways you can write the ready() event handler :

//1- one way to call the ready function.
// Our code here...

//2- Second way to call the ready function.
// Our code here...

//3- Third way to call the ready function.
// Our code here...

All the above three ready handler has same functionality you can call the ready handler whichever style you like.

Event Handling (Event Attachment):

Below is the list of the event handling taken from the documentation of events from jquery site. List 1

Event Name Description
bind(type,data,fn) Binds a handler to one or more events (like click) for each matched element. Can also bind custom events.
one(type,data,fn) Binds a handler to one or more events to be executed once for each matched element.
trigger(type,data) Trigger a type of event on every matched element.
triggerHandler(type,data) This particular method triggers all bound event handlers on an element (for a specific event type) WITHOUT executing the browser's default actions.
unbind(type,fn) This does the opposite of bind, it removes bound events from each of the matched elements.

The return type of the above events are the jquery object. which is used for chainablility , to apply more functions on that return control object. when you call above enent handler/attachers, you can set the type of the event by one of the below list. List 2
Event Name Event Name Event Name
blurchange focus
click dbclick error
keydown keypress keyup
mousedown mousemove mouseout
mouseover mouseup resize
scroll select submit
load unload

These are the possible value of the type which is set in the event binding. Let us start with the bind event handler.


The bind() event handler is use to bind the event with the object.You can see from List 1 parameter of the bind events are the type ( which i have mentioned in the List 2), data(optional parameter) and event handler.Here is the example how you can use the bind event handler to bind the event with the object.

$( "p").bind("click", function(e){
var str = "( " + e.pageX + ", " + e.pageY + ")";

$( "p").bind("dblclick", function(){
alert("Double-click happened" );

$( "p").bind("mouseenter mouseleave", function(e){
$(this).toggleClass( "over");


Above code is simple one it bind the click event , dbClick and the mouse enter and mouse leave events for the paragraph tag. and you can also see how to set the type of the event in the bind event handler and also it attach anonymous callback function. The anonymous callback function which is attached with the click event is passed an event object which i will explain next. And the event handler which is attached with the dbclick didn't passed any parameter. Let me explain the event object which is passed to the event handler so you get some idea why we need to pass event object to the event handler.

The Event Object:

The callback function which is attached using the above list event handler can also take optional parameter which is used for additional information in the callback function.The additional information include such as .shiftKey (whether the shift key was held down at the time), .offsetX (the x coordinate of the mouse cursor within the element), and .type (the kind of event this is). Some of the event object's attributes and methods are not available on every platform. If the event is handled by a jQuery event handler, however, the library standardizes certain attributes so that they can be safely used on any browser. In particular:
This attribute represents the DOM element that initiated the event. It is often useful to compare to this in order to determine if the event is being handled due to event bubbling.

This attribute contains the x coordinate of the mouse cursor relative to the left edge of the page.


This attribute contains the y coordinate of the mouse cursor relative to the top edge of the page.

If this method is called, the default action of the event will not be triggered. For example, clicked anchors will not take the browser to a new URL.

This method prevents the event from bubbling up the DOM tree looking for more event handlers to trigger.

Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object. Note the parameter added to the anonymous function. You can omit the event object, if you need additional information regarding the event then you can pass the event object else no need to pass the event object.

Passing Event Data:
Now here is the code to bind the event with object using the bind event handler and also pass the data as well.The code below is taken from Infovore
$("#myDiv").bind("click",{myValue:'Some Value'}, handleToggleEvent);

function handleToggleEvent(event)

In the above code you can see i have bind the click event for the div control , the id of the div is myDiv as you can see from the selector. and i have pass the value is key : value, which mean if i have to access the value which is passed then i need to call in the event handler, which is set at third parameter in the bind event handler.


The unbind event handler is opposite to the bind event handler as it unbind any event attached to the object. From the List 1 you can see the the it has the following form

where type is one of the type i have mentioned in List 2 , e.g 'click', 'dbclick' or any of the type which is listed in the List 2.

//1- one way to call

//2- Second way to call

//3- Third way to call
$("#controlID").unbind(type, callback);

The first call to unbind the callback will unbind all the callback from the "ControlID" , The second call is more specific as it will remove the only callback whose type is give, for example if you give the type "click" then it will remove the callback which are bind for the click event handler. and the third one is specific then the first 2 as it will unbind the event which is passed either "click" or any of the type which is listed in the List 2 and then then remove the callback which is passed as well.


The next one is the one event handler. The one event handler as its name suggest is executed only once and is similar to the bind event handler except that event is fire once , mean if you for example attach event handler for a control on its click once you click the button the code is executed but if you click again the button then the code is not executed. It is similar to that you unbind the callback, once the event is fired and you don't want to execute the code again. And here is the call to the one event handler.

you can see that it is similar to the bind event handler , same type parameter, same optional data parameter and same callback function parameter.


The trigger event handler is used to execute the specific callback function, which is attached using the bind event handler.

hope you will get enough to start with the event handler , if you have any question please ask me
happy programming :)

back to content

Saturday, December 13, 2008

Jquery for Beginners

Every web developer not all 100% but i think 99% of developer must use the javascript in there project, for input validation , showing and hiding of the controls, slowly showing and slowly hiding etc .They have used the javascript in there project and they have write same code again and again in different projects or even in different form/pages. I personally love to use javascript in my web application where it is necessary and i love javascript coding. During my search on the javascript on net i have found many javascript libraries which can be use to achieve functionalists which i have mention above. The libraries include prototype, mootoo , jquery etc. All of these libraries are really good. But i have use the jquery and try to get more out of jquery library.
Let us start how we can start with jquery. First of all you have to get latest version of the jquery file from the jquery web site.

for user i have pasted the image of the location from where you can download the jquery file. as you can see there are two files which has same, the difference is in there size one is for production and one is for Development, you can download one of this or both. You can download the production file from jquery-1.2.6.min.js 54.5 KB. Next you have to include the jquery file into your page like this

<script src="scripts/jquery.js" type="text/javascript"></script>

And this is the simple starting point for you reader who are just new to the jquery. you have to put this code in the script tag of type 'text/javascript'.

$(document).ready( function()
alert('Hello world');

The above code is simple one and it contain just hello world message which is shown when the page is fully loaded. But this code contain the basic things you need to start with, first of all the dollar ($) sign, which is call the selector, if you want to select any control in the you page then you can use this dollar sign to get that control suppose you have the control whose id is "cmdButton" then what you need is to get that button but using $('#cmdButton') statement, One more important thing which i would like to share with you is that the syntax above to get the control is used when you don't have master page in you project, or your page didn't open in master page but if your page is open in your master page then what you need to do is to get the control is $('#'+'<%=cmdButton.ClientID%>') this syntax is used to get the control in jquery.

From the code above you have seen the number sign (#) The number sign is used to select the control/element by there id. You can select element by there css className, with there ElementTag and even with the element properties etc for complete referece how you can access the elements you can click here . For quick reference some of the how to access the elements.
  • To access element with there id , where myDiv is the id of the div control in the page.
    $("#myDiv").css("border","3pxsolid red");
  • To access element with there tag name . This example will apply red border of red color to all the divs in the page regardless of the id and the class name.
    $("div").css("border","3px solid red");
  • To access element with there css className . The example below will access the control whose css class name is myClass and apply the red border of 3px to every control which has myClass css class name.
    $(".myClass").css("border","3px solid red");
Now come to the $(document).ready(function(){}); event handler .This is the first thing to learn about jQuery: If you want an event to work on your page, you should call it inside the $(document).ready(function())}. Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded (Source). The question which may come into your mind is why we need the $(document).ready(function(){}); The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this:
 window.onload = function(){ alert("welcome"); }

Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is due to the fact that the HTML 'document' isn't finished loading yet, when you first try to run your code. To circumvent both problems, jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event (Source)

why we need to use jquery, as you can see the syntax of the jquery is very easy to learn and easy to read.Second think which i like about jquery is that if you call one jquery function then that function will return same object, which is chainability , mean you can apply as many function by place the (.) dot sign and call the next function and so on and on.

Hope you like this. if you have any question then ask me.

back to content

Saturday, December 6, 2008

SqlCommand Parameter And Sql injection

Sql injection can be prevented using sqlCommand parameter, and i will show you how can we use sqlCommand paramenter to avoid the sql injection.When i think of sql injection first question that came to my mind is what is sql injection. Definition of sql injection is (Wikipedia)

A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application.

A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system. SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands.
So in order to avoid such attack from hackers we need to check for invalid input from the user. Some programmer who are really good convert single quote to double quote, by writing the function, Some programmer not allowed user to enter such characters in input fields and so on and on.But the way today i will discuss is using sqlCommand parameter to avoid such attacks. Input used for this test application are as fellow.

User Name: asimsajjad';Drop Table tblUser;'

Password: 123

I have used Same database of northwind and same tblUser which i have show in my sqlCommand parameter post.First i have tested for the sqlCommand parameter so that i don't need to create tblUser table again. Hope you will create the HTML for your page as i will not write HTML code of the my test here. The .cs code which i have write on the cmdSave_Click event handler is pasted here, you can copy paste the code and change the UID and pwd with the sql server user name and password.

protected void cmdSave_Click(object sender, EventArgs e)




SqlConnection sqlConnection = new SqlConnection("Data Source=localhost; UID=UserName; PWD=Password; Initial Catalog=northwind;");


string strQuery = "Select userID from tblUser where UserLoginName=@UserLoginName";

SqlCommand sqlCommand = new SqlCommand (strQuery, sqlConnection);

sqlCommand.Parameters.AddWithValue("@UserLoginName", txtLoginName.Text);

int intUserID=Convert .ToInt32(sqlCommand.ExecuteScalar());

catch (Exception Ex)

//handle the exception here;



The above code is simple one. i have declared and initialize the sqlConnection object and pass the connection string to the sqlConnection constructor. After initializing the sqlConnection object i have open the connection object. Then i have declared the string object to hold the sqlCommand. Next i have declared the sqlCommand object and initialized the sqlCommand with query and sqlCommand object. In the next line i have added the the value of the parameter which i have used in the query. With the above input the value is saved in the tblUser table and there is no error and no sql injection as , i have inserted Drop Table tblUser; statement in the user name field. But using sqlCommand parameter the table is not dropped.
But when i use the code below with same parameters as above then the tblUser table is drop from the database. Which confirms that dynamic query can't stop the sql injection.

protected void cmdSave_Click(object sender, EventArgs e)




SqlConnection sqlConnection = new SqlConnection("Data Source=localhost; UID=UserName; PWD=Password; Initial Catalog=northwind;");


string strQuery = string.Concat("Select userID from tblUser where UserLoginName='", txtLoginName.Text,"'");

SqlCommand sqlCommand = new SqlCommand (strQuery, sqlConnection);
int intUserID=Convert .ToInt32(sqlCommand.ExecuteScalar());

catch (Exception Ex)

//handle the exception here;



When i posted my first post on sqlCommand parameter one of my reader ask question "does using parameters in sql command prevent sql injection?" , I also mention is that post the using sqlCommand parameter we can prevent the sql Injection, So from my above test i can answer you confidently yes.
The Guidlines of avoiding the such attacks are (How To: Protect From SQL Injection in ASP.NET)
  • Constrain and sanitize input data. Check for known good data by validating for type, length, format, and range.
  • Use type-safe SQL parameters for data access. You can use these parameters with stored procedures or dynamically constructed SQL command strings. Parameter collections such as SqlParameterCollection provide type checking and length validation. If you use a parameters collection, input is treated as a literal value, and SQL Server does not treat it as executable code. An additional benefit of using a parameters collection is that you can enforce type and length checks. Values outside of the range trigger an exception. This is a good example of defense in depth.
  • Use an account that has restricted permissions in the database. Ideally, you should only grant execute permissions to selected stored procedures in the database and provide no direct table access.
  • Avoid disclosing database error information. In the event of database errors, make sure you do not disclose detailed error messages to the user.
Some of the benefit other then i have mention in sqlCommand parameter are
It is faster when executing parametrized command over query string..("MSDN Forum")
2) The second-order attack would not have been possible if parameterised queries had been used.(Code Project). Second-order attack is "it may be possible for an attacker to inject their malicious code into a data storage area that may be executed at a later date or time. Depending upon the nature of the application and the way the malicious data is stored or rendered, the attacker may be able to conduct a second-order code injection attack. " (Source)

Hope this will help.

Friday, December 5, 2008

JavaScript ToolTip

Today i will discuss tooltip in javascript how can you create it and use it very quickly in your code. I have seen that there is no such control for tooltip in, so the developer try to design there own tooltip. Some of the control in the has the property tooltip but not all has. So in order to show the tooltop for those control here is the little javascript code to use it. This Sample Javascript code is taken from the Itookia, and I have modified the code according to my need and also the i have use the stylesheet for the formatting.

and the tooltip which contain the help information .

and tooltip which contain the image.

The Css used for this tooltip which i have changed is takend from Itookia



filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,

StartColorStr=#ffffff, EndColorStr=#cecfde);

cursor: hand;

width: 300px;

font-size: 11px;

padding-left: 5px;

padding-right: 5px;

border: 1px solid #7b9ebd;

position: absolute;

visibility: hidden;




padding: 6px 0 4px 10px;

font: bold 12px Trebuchet MS ,Arial;

float: left;

clear: both;

width: 100%;




font: normal 12px Trebuchet MS, Arial;

padding: 0 2px 6px 20px;

margin: 0;

float: left;




font: bold 12px Trebuchet MS ,Arial;

margin-right: 10px;

border: #BDBDBD 1px solid;

float: left;


The javascript code which i have modified is

var lastTooltip =null;

showTooltip = function (strTitle,strText,strHelpText,strhelpImage,strmainImage)


if (lastTooltip==null)


var newDiv = document.createElement("div");


var title = document.createElement("span");


var titleText = document.createTextNode(strTitle);


var mainParagraph = document.createElement("p");


if (strmainImage)


var mainImg = document.createElement("img");



mainParagraph.appendChild(mainImg); }

var mainText = document.createTextNode(strText);




if (strHelpText)


var horLine = document.createElement("hr");'96%';'both';

var helpDiv = document.createElement("div");'left';'left';'both';'6px';'24px';

if (strhelpImage)


var helpImg = document.createElement("img");




var helpText = document.createTextNode(strHelpText);






if (document.addEventListener)

document.addEventListener("mousemove",moveTooltip, true);

if (document.attachEvent)


var bodyRef = document.getElementsByTagName("body").item(0);




moveTooltip = function (e)




if (document.all)

e = event;

if (

sourceEl =;

else if (e.srcElement)

sourceEl = e.srcElement;

var coors=findPos(sourceEl);

var positionLeft = e.clientX;

var positionTop = coors[1] + sourceEl.clientHeight + 1;'px';'px';'visible';



hideTooltip = function ()


var bodyRef = document.getElementsByTagName("body").item(0);

if (lastTooltip)




function findPos(obj)


var curleft = curtop = 0;

if (obj.offsetParent)


curleft = obj.offsetLeft

curtop = obj.offsetTop

while (obj = obj.offsetParent)


curleft += obj.offsetLeft curtop += obj.offsetTop



return [curleft,curtop];


and the javascript function calls for all the above image show are

onmouseover="showTooltip('Simple tooltip','This is simple tooltip')"


onmouseover="showTooltip('Simpe tooltip with additional info','This is simple tooltip with additional help info.','Press F1 for more help.','help.png','')"
= "hideTooltip()"

onmouseover="showTooltip('Complex tooltip','This is complex tooltip with image.','Press F1 for more help.','help.png','graf.png')"


Hope you will like this post for the tooltip in using javascript :)
you can now download source code from here

Monday, December 1, 2008

SqlCommand Parameters

Today i will discuss the sqlCommand Parameters which i have not used before this, and i was unaware of the power of the sqlCommand Parameter. Before this i was using the dynamic query by concatenating the string and then executing that query to fetch, update delete the record from database.
I have read the following 2 article Dynamic SQL Needs to die and Dynamic SQL Can Die Automatically and i find these article very useful.
Lets start by Example then i will give the conclusion at the end.
i have created simple table name tblUser in the northwind database and table name is tblUser and is shown below.

and i have following one value in the database for my testing.

The user interface is quite simple which consist of User name , password and login button. In the image below i have set the value of the user name and password which are use name is "asim" and Password "123'3". As you can see in my example input , for user i have not set the password field property " TextMode" to Password.So that user can see the input clearly.

No when i execute the sqlcommand for dynamic query which use the concatenation of the values with the string and generate the query you can see clearly in the image blog that it will give Exception of "Incorrect syntax near '3'.\r\nUnclosed quotation mark after the character string"," and this exception often occure if we don't convert single quote to double in our code.

And when i use sqlCommand with same parameters which contain single quote in the password there is not exception in the execution of the command and i got the smoth execution of the command and result. As you can see in the image blow.

Now i am happy to knew the power of sqlCommand and ready to use it in the my new projects. The Benefits of using the sqlCommand are as fellow taken from Dynamic SQL Needs to die.

1) Single Quote.

If I forgot one of the apostrophes. The code would compile and everything would appear to be fine. However, once I executed the command, it would blow up and result in a Syntax error. This is an easy mistake to make no matter how careful you are. Also, pretend you had 15 values in the Where clause. It'd be a feat indeed to get it right the first time. Another common thing that comes up is that you can just write a function that changes the single quotes to double quotes so it can be used. Well, you'll have to call this on every SQL statement to safely assume it will work. You'll probably forget to do it at least once, and other programmers may forget it or not know that you have this function when they maintain your code.

2) Data Type

Another example is Date fields. Different RDBMS implementations require a different Date Format. It's very easy to forget about this and forget one of the critical formatting chunks. Again, if you are totally careful you probably won't make many mistakes here, but your new programmers probably will. Someone editing your code probably will etc.Another problem is fields that have an apostrophe in them. This happens so often it's amazing.

3) It's a preformance killer.

Your query won't be able to take advantage of cached execution plans. That means that the same query can hit the db over and over again and each time the Server won't be able to reuse plans it's already cached.

Sunday, November 16, 2008

Curvy Corner

During your net surfing you may have seen web site which contain rounded box. These rounded box are created by the images which contain the rounded corners and the border as well. So web developer like me who don't have idea of adobe photoshop or tools which are used to created these images have to learn the tool first to create the rounded images and then use them in there web site. or you may ask the graphics designer to create images for you as per your need. But a good new for developer like me who don't have knowledge how to create rounded image they can create rounded box without any image. Curvy Corner is the javascript code use to create the rounded box and it is really easy. Curvy Corner is a javascript file you can use it to created the rounded box. In this article i will try to demonstrate how you can use the curvy corner javascript code to create the rounded box.
First of all you have to download the latest verion of the curvy corner file from here. In the folder you have extracted from the downloaded zip file you will contain two javascript files

1- curvycorners.js which is compressed file and its size is 16 k
2- curvycorners.src.js which uncompressed file and its size is 47k and is is readable

and also the demo html file as well and some other stuff related to th demo html pages.
First you have to place the curvyCorner.js which is of 16 k in javascript folder of your project or any where you like i have placed it in js folder of my project.

in my .aspx page in the header firt i have include the javascript file by setting the src property of the script tag


and i have write the code to create the divs here is example code image i have only shown the div tag and there properties settings.

from the image you can see i have created outer div which contain two divs.The java script to round the corner of the inner div and the bottom corner of the outer div is as below.

function OnloadFunction()
settings = {
tl: { radius: 7 },
tr: { radius: 7 },
bl: { radius: 7 },
br: { radius: 7 },
antiAlias: true,
autoPad: true

MainDivsettings = {
bl: { radius: 5 },
br: { radius: 5 },
antiAlias: true,
autoPad: false

var DivFirst=document.getElementById('DivFirst');
var DivSecond= document.getElementById("DivSecond");
var DivMain = document.getElementById("DivMain");

var DivFirst = new curvyCorners(settings, DivFirst);

var DivSecond= new curvyCorners(settings,DivSecond);

var DivMain= new curvyCorners(MainDivsettings,DivMain);


The Settings
The first part of the previous example creates a variable called settings, you can change this to any variable name you want, you will need to use this variable later on in the script. This variable holds all the settings needed for the curvyCorners object to work. Each line of the settings object is a particular setting, for example the first line tl: { radius: 7 }, tells the script that you want the top right corner of your box to have a 7 pixel corner radius. The next three lines set the radiuses for the other three corners.

if you don't want the corner to be rounded and the corner remain the square then you can set that corner value to be false. In the example javascript code i don't want the top right and top left corner of the outer div to be rounded so replace the bracketed section to the right of each colon (:) with the keyword false. See example the MainDivsettings in the above code.


Changing the value of antiAlias from true to false will toggle the anti-aliasing. Turning off anti-aliasing will reduce the smoothness of the corners but will greatly increase the rendering time required to draw the corners.


The last setting is called autoPad. Again this can be set to either true or false. By default and DIVs that make use of the curvyCorners can't have padding applied. This is because the padding messes up the corners that curvyCorners generates.

you can find more detail about how to use curvy corner by clicking here

the css class i have used for my code example is

border: #6593cf 1px solid;
padding: 2px 2px 2px 2px;
margin: 0px auto;
color: #000;
background-color: #f1f5fa;

and the output of my example is as below

Enjoy rounded corner box without images :)

and output with the firefox is even better

Saturday, November 15, 2008

Consolas Font Pack for Microsoft Visual Studio 2005 or 2008

Microsoft consolas is the font microsoft has design for the IDE like studio 2005 and 2008 and is Optimized for Microsoft ClearType. The Microsoft Consolas Font Family is a set of highly legible fonts designed for ClearType. It is intended for use in programming environments and other circumstances where a monospaced font is specified. This installation package will set the default font for Visual Studio to Consolas. I have using Microsoft Consolas for 10 to 12 days and i really like this font.

You can download version 1.0 of Microsoft Consolas from here and install the font.

The font is really cool and you will also like this font when you spend some time with this font. There is some little error if you look at the font.

if you look at the character M then it is not looking good i hope microsoft will correct it in the next release of consolas

Friday, November 14, 2008

Visual Studio Theme

I was always looking for new look in every think like window theme, and in web applications and want to create and search new look of the web applications on the net and spends hours and hours, I also use to try new thing in the Visual Studio editor as well, the one thing which i do whenever i use new pc for development or i install new visual studio is to change the font and the color of the string in between double quotes and i like string in the format like
"This is the Test String"

After my Search on net i have found serveral theme regarding visual studio 2005 you can try yourself and download from here and also look at this link as well.

as i have downloaded my favorite and using it :)

How to Use Theme ?

First you have to download one of your favorite theme fromt the link i have mention above and you will get the zip file which you have to extract and you will ge "Darkness.vssettings" . and here are the steps you have to follow thAdd Imageese steps.

Go to the Tools->Option and then
Step 1: Select Import and Export Settings
Step 2: Check the "Use Team Settings file" option
Step 3: Click the Browse button to locate your File.vsssettiongs file

Enjoy new theme.

Saturday, November 8, 2008

Parse and TryParse Methods - Difference

I have a question in mind for last 1 to 3 months but during this period i was very busy and didn't get time to get answer to my question. The question was
"What is difference between the Parse and TryParese Method ?"
Now i got the time and get answer of my question and the answer to my question is given by Blogging Developer
You can read this article and you will fine what is the difference between the Parse and TryParse method, in this article author also compare them with the convert method but as my question was difference between the Parse and TryParse so here is the difference between them.

Parse: This function takes a string and tries to extract an integer from it and returns the integer. If the string is not a numerical value, the method throws FormatException. If the extracted number is too big, it throws OverflowException. Finally, if the string value is null, it throws ArgumentNullException.
Example: Int32 intValue = Int32.Parse(str);

TryParse: This function is new in .Net 2.0. Since exception handling is very slow, TryParse function returns a boolean indicating if it was able to successfully parse a number instead of throwing an exception. Therefore, you have to pass into TryParse both the string to be parsed and an out parameter to fill in. Using the TryParse static method, you can avoid the exception and ambiguous result when the string is null.

Example : bool isParsed = Int32.TryParse(str, out intValue);

From the above reading you can see that Parse function will throw 3 exceptions which are
1- FormatException

mean when you are using Parse function then there is possibility of 3 exception and when you are using TryParse then there is no such exception only you need to check the Boolean value which is return from the TryParse Function. So my Recommendation is try to Use TryParse and avoid the exceptions.