Saturday, 10 December 2011

Fading image using jquery FadeTo


<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
<script>
window.setInterval("Method()", 1000);
Method = function () {
var ff = parseFloat($("img").css("opacity")).toFixed(1);
// alert(ff);
if (ff == 0.6)
$("img").fadeTo("slow", 1);
else
$("img").fadeTo("slow", 0.6);
};
</script>


<img border="0" src="Images/Bald.jpg" width="400" />

Share:

Tuesday, 6 December 2011

Populate Select from ajax with jquery

<head>
<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {

$.ajax({ url: "Fetchdata.ashx",
type: "GET",
dataType : 'json',
success: function (msg) {

$("#ddlcity").get(0).options.length = 0;
$("#ddlcity").get(0).options[0] = new Option("Select City", "-1");

$.each(msg, function (k, v) {
//alert(v);
$("#ddlcity").get(0).options[$("#ddlcity").get(0).options.length] = new Option(v.Name, v.ID);
});
},
error: function (msg) { alert("Error !!!!"); }
});
});
</script>

</head>
<body>
<select id="ddlcity"></select>
</body>


<%@ WebHandler Language="C#" Class="Fetchdata" %>

using System;
using System.Web;
using System.Collections.Generic;
public class Fetchdata : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
List Objcity = GetList();
System.Web.Script.Serialization.JavaScriptSerializer objJs = new System.Web.Script.Serialization.JavaScriptSerializer();
context.Response.Write( objJs.Serialize(Objcity));
}

public bool IsReusable {
get {
return false;
}
}
public List GetList()
{
List <Citydata> item = new List<Citydata>();
item.Add(new Citydata() { Name = "Delhi", Id = "1" });
item.Add(new Citydata() { Name = "Mumbai", Id = "2" });
item.Add(new Citydata() { Name = "Kolcatta", Id = "3" });
item.Add(new Citydata() { Name = "Chennai", Id = "4" });
item.Add(new Citydata() { Name = "Banglore", Id = "5" });
item.Add(new Citydata() { Name = "Agra", Id = "6" });
return item;
}
}

public class Citydata
{
string _Name = string.Empty;

public string Name
{
get { return _Name; }
set { _Name = value; }
}
string _Id = string.Empty;

public string Id
{
get { return _Id; }
set { _Id = value; }
}

}
Share:

Monday, 7 November 2011

server side validation using regular expression and extension method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DAL
{
public static class Extention
{
const string MatchEmailPattern =
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

const string NumberPattern=@"^\d$";
const string AlphbetPattern = @"^[a-zA-Z]*$";
const string AlphanumricPattern = @"^[a-zA-Z0-9]*$";
const string AlphNumeric_space = @"[^\w\s]";
const string AlphaNumeric_spacial = @"^((?:[A-Za-z0-9-'.,@:?!()$#/\\]+|&[^#])*&?)$";
const string AlphaNumeric_Hyphen = @"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$";
//Date Constant/////////////////
const string Dateyyyydddmm_pattern = @"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
const string Datemmddyyyy_Pattern = @"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$";
const string Dateddmmyyyy_Pattern = @"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$";
const string DateddMMMyyyy_Pattern = @"^(0[1-9]|1[012])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[-
/.](19|20)\d\d$";

const string
Url_Pattern=@"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,|
|>|<|;|\)])";
public static bool IsEmail(this string value)
{
if (value != null)
return System.Text.RegularExpressions.Regex.IsMatch(value, MatchEmailPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsNumber(this string value)
{
if (value != string.Empty)
return System.Text.RegularExpressions.Regex.IsMatch(value, NumberPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;

}
public static bool IsAlphabet(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, AlphbetPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsAlphaNumeric(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, AlphanumricPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsAlphaNumeric_Space(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, AlphNumeric_space,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsAlphaNumeric_Spacial(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumeric_spacial,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsAlphaNumeric_Hyphen(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumeric_Hyphen,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsDateyyyydddmm(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, Dateyyyydddmm_pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}

public static bool IsDatemmddyyyy(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, Datemmddyyyy_Pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsDateddmmyyyy(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, Dateddmmyyyy_Pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsDateddMMMyyyy(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value,
DateddMMMyyyy_Pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
public static bool IsUrl_Valid(this string value)
{
if (!string.IsNullOrEmpty(value))
return System.Text.RegularExpressions.Regex.IsMatch(value, Url_Pattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
else
return false;
}
}

}
Share: