Generating Random Image on a button Click
public static string GetRandomPassword(int length)
{
Random rand = new Random();
System.Text.StringBuilder password = new System.Text.StringBuilder(length);
for (int i = 1; i <= length; i++)
{
int charIndex;
do {
charIndex = rand.Next(48, 123);
}
while (!((charIndex >= 48 && charIndex <= 57) ||(charIndex >= 65 && charIndex <= 90)|| (charIndex >= 97 && charIndex <= 122)));
// add the random char to the password being built
password.Append(Convert.ToChar(charIndex));
}
return password.ToString();
}
private void GenerateImage(string strRegistrationStr)
{
System.Drawing.Bitmap objBitmap = new Bitmap(150, 30);
Graphics objGraphics = Graphics.FromImage(objBitmap);
//Fore Color and Background of Image
SolidBrush objForeColor = new SolidBrush(Color.White);
SolidBrush objBackColor = new SolidBrush(Color.Black);
objGraphics.FillRectangle(objBackColor, 0, 0, 150, 30);
//Font settings for Image
Font objFont = new Font("Arial", 15);
//Display from 5point from x-axis and 5point from y-axis
Point objPoint = new Point(5, 5);
//Drawing Registration String
objGraphics.DrawString(strRegistrationStr, objFont, objForeColor, objPoint);
//Saving Registration String as Image
//If you dont want image to save
//objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
//otherwise use this
objBitmap.Save(Server.MapPath("RegistrationImg.gif"), ImageFormat.Gif);
//Release object
if (objBitmap != null)
objBitmap.Dispose();
if (objGraphics != null)
objGraphics.Dispose();
}
protected void butRegister_Click(object sender, EventArgs e)
{
GenerateImage(GetRandomPassword(10));
ImgRegistrationStr.ImageUrl = "RegistrationImg.gif";
}
Thanks,
Nitin Sharma
Thursday, December 18, 2008
Tuesday, December 16, 2008
Fetching QueryString Parameters by Javascript
script language="javascript" type="text/javascript"
// Create a new QueryString object
//alert( window.top.location.search.substring(1));
var qrStr = window.location.search;
var spQrStr = qrStr.substring(1);
var arrQrStr = new Array();
// splits each of pair
var arr = spQrStr.split("&");
for (var i=0;i // splits each of field-value pair
var index = arr[i].indexOf("=");
var key = arr[i].substring(0,index);
var val = arr[i].substring(index+1);
// saves each of field-value pair in an array variable
arrQrStr[key] = val;
}
alert("Parameter:" + arrQrStr["company"]);
script
you just change the name of the paremeter in the alert('Parameter Name: '+ arrQrStr["company"]);
Here it is Company
Thanks,
Nitin Sharma
// Create a new QueryString object
//alert( window.top.location.search.substring(1));
var qrStr = window.location.search;
var spQrStr = qrStr.substring(1);
var arrQrStr = new Array();
// splits each of pair
var arr = spQrStr.split("&");
for (var i=0;i
var index = arr[i].indexOf("=");
var key = arr[i].substring(0,index);
var val = arr[i].substring(index+1);
// saves each of field-value pair in an array variable
arrQrStr[key] = val;
}
alert("Parameter:" + arrQrStr["company"]);
script
you just change the name of the paremeter in the alert('Parameter Name: '+ arrQrStr["company"]);
Here it is Company
Thanks,
Nitin Sharma
Monday, December 15, 2008
create,Read and erase Cookie in Javascript
The scripts
These are the three scripts you need
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
Thanks,
Nitin Sharma
These are the three scripts you need
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
Thanks,
Nitin Sharma
Subscribe to:
Posts (Atom)