November 2011

Resize image while uploading image

Namespace required:
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
— .cs page coding on Save button—————–
// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(newBMP);

// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);

// Save the new graphic file to the server
newBMP.Save(Server.MapPath(“~/StaffImages/” + StaffId + Path.GetExtension(fupImage.FileName)));

// Once finished with the bitmap objects, we deallocate them.

How to remove white space from TEXTAREA?

function removeTextAreaWhiteSpace() {
var myTxtArea = document.getElementById(‘txtQuestion’);
myTxtArea.value = myTxtArea.value.replace(/^\s*|\s*$/g, ”);

Call above function “removeTextAreaWhiteSpace()” onfocus event of textarea. e.g. onfocus=”removeTextAreaWhiteSpace()”

Change body background on Page Reference

Call javascruot function on body load event… e.g. ”

var totalCount = 5;
function Test() {
// if (document.body) {
// = ‘url(images/slideshow1_1.jpg)’;
// }

var num = Math.ceil(Math.random() * totalCount);
if (num == 1) {
//document.bgColor = “Red”; = ‘url(images/slideshow1_1.jpg)’;
else if (num == 2) {
//document.bgColor = “Yellow”; = ‘url( images/slideshow1_2.jpg)’;
else if (num == 3) {
//document.bgColor = “Green”; = ‘url(images/slideshow1_3.jpg)’;
else if (num == 4) {
//document.bgColor = “Blue”; = ‘url(images/slideshow1_4.jpg)’;
else if (num == 5) {
//document.bgColor = “White”; = ‘url(images/slideshow1_2.jpg)’;

this is my page

you can also use like this in javascript

var backImage = [

function changeBGImage(whichImage) {
if (document.body){ = ‘url(‘+backImage[whichImage]+’)’;


JQuery Validations

Above link includes all validation. Its so pretty web site look like more pretty.



Get URL Parameters (QueryStrings) using Javascript

Get URL Parameters (QueryStrings) using Javascript

Nearly all server-side programming languages have built-in functions to retrieve querystring values of a URL. In web browsers you can access the querystring with client-side JavaScript, but there is no standard way to parse out the name/value pairs. So here is a function to return a parameter you specify. The following javascript code snippet facilitates Javascript’s built in regular expressions to retrieve value of the key. Optionally, you can specify a default value to return when key does not exist.

function getQuerystring(key, default_)
if (default_==null) default_=””;
key = key.replace(/[\[]/,”\\\[“).replace(/[\]]/,”\\\]”);
var regex = new RegExp(“[\\?&]”+key+”=([^&#]*)”);
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
return qs[1];

The getQuerystring function is simple to use. Let’s say you have the following URL:

and you want to get the “author” querystring’s value:

var author_value = getQuerystring(‘author’);