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.
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();

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) {
// document.body.style.backgroundImage = ‘url(images/slideshow1_1.jpg)’;
// }

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

this is my page

you can also use like this in javascript

var backImage = [
“images/bg0.png”,
“images/bg1.png”,
“images/bg2.png”,
“images/bg3.png”,
“images/bg4.png”,
“images/bg5.png”
];

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

download: https://skydrive.live.com/?cid=efc0ec2e2cd761ee&sc=documents&nl=1&uc=1&id=EFC0EC2E2CD761EE%21164#

JQuery Validations

http://www.position-relative.net/creation/formValidator/

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

Download: https://github.com/posabsolute/jQuery-Validation-Engine

or https://skydrive.live.com/?cid=efc0ec2e2cd761ee&sc=documents&nl=1&uc=1&id=EFC0EC2E2CD761EE%21160#

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_;
else
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’);