Saturday, December 10, 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" />

Tuesday, December 6, 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; }
}

}

Monday, November 7, 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;
}
}

}

Saturday, October 1, 2011

custom paging in datagrid-repeater-gridview

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>







using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int totalRecords = 234;
int pageSize = 10;
int totalPages = totalRecords / pageSize + (totalRecords % pageSize > 0 ? 1 : 0);
int NoofNumaricLink = 7;
int currentPage = 1;
if (Request.QueryString["page"] == null)
currentPage = 1;
if (Request.QueryString["page"] != null)
{
if (!int.TryParse(Request.QueryString["page"].ToString(), out currentPage))
currentPage = 1;
if (currentPage > totalPages)
currentPage = totalPages;
}

List <Customer> customers =(new Customer()).GetCustomerList();

var ObjCustomerslist = customers.Skip((currentPage - 1)*pageSize).Take(pageSize);
Dgpager.DataSource = ObjCustomerslist;
Dgpager.DataBind();
litPaging.Text = CreatePageLinks(totalRecords, pageSize, totalPages, NoofNumaricLink,currentPage);

}

string CreatePageLinks(int totalRecords, int pageSize, int totalPages, int TotalNoLink, int currentPage)
{
if (totalRecords <= pageSize)
return "";
StringBuilder strPager = new StringBuilder();

string pageUrl = Context.Request.Url.AbsolutePath;

if (currentPage > 1)
{
strPager.Append(string.Format("Fist", 1, pageUrl));
strPager.Append(string.Format("Previous", (currentPage - 2) + 1,
pageUrl));
}
if(!(currentPage > 1))
{
strPager.Append("FirstPrevious");
}
int min, max;
if (TotalNoLink >= totalPages)
{
min = 1;
max = totalPages;
}
else
{
if (currentPage - TotalNoLink / 2 > 0)
max = (currentPage + TotalNoLink / 2 - (TotalNoLink - 1) % 2);
else
max = TotalNoLink;
if (max > totalPages) max = totalPages;
min = max - TotalNoLink + 1 > 0 ? max - TotalNoLink + 1 : 1;
}
for (int n = min; n <= max; n++)
{
if (n > totalPages)
break;
if (n == currentPage)
strPager.Append(String.Format(" {0}", n.ToString()));
else
strPager.Append(String.Format("{0} ", n, (n - 1) + 1,pageUrl));
}
if (currentPage < totalPages)
{
strPager.Append(String.Format("Next ", currentPage + 1, pageUrl));
strPager.Append(String.Format("Last ", totalPages, pageUrl));
}
if (!(currentPage < totalPages))
{
strPager.Append("NextLast");
}

return strPager.ToString();
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Customer
{
string uid = string.Empty;

public string Uid
{
get { return uid; }
set { uid = value; }
}
string name = string.Empty;

public string Name
{
get { return name; }
set { name = value; }
}
int age = 0;

public int Age
{
get { return age; }
set { age = value; }
}
public List <Customer> GetCustomerList()
{
List <Customer> listitem = new List <Customer>();
for (int n = 1; n < 245; n++)
{
listitem.Add(new Customer() { Uid = n.ToString(), Name = "name" + n.ToString(), Age = n * 10 });
}
return listitem;
}
}

Tuesday, September 27, 2011

Google like Paging in Asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>










using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int totalRecords = 234;
int pageSize = 10;
int totalPages = totalRecords / pageSize + (totalRecords % pageSize > 0 ? 1 : 0);
int NoofNumaricLink = 7;
litPaging.Text = CreatePageLinks(totalRecords, pageSize, totalPages, NoofNumaricLink);

}
string CreatePageLinks(int totalRecords, int pageSize,int totalPages, int TotalNoLink)
{
if (totalRecords <= pageSize)
return "";
StringBuilder strPager = new StringBuilder();
int currentPage = 1;
string pageUrl = Context.Request.Url.AbsolutePath;
if (Request.QueryString["page"] == null)
currentPage = 1;
if (Request.QueryString["page"] != null)
{
if (!int.TryParse(Request.QueryString["page"].ToString(), out currentPage))
currentPage = 1;
if (currentPage > totalPages)
currentPage = totalPages;
}
if (currentPage > 1)
strPager.Append(string.Format("Previous", (currentPage - 2) + 1, pageUrl));
int min, max;
if (TotalNoLink >= totalPages)
{
min = 1;
max = totalPages;
}
else
{
if (currentPage - TotalNoLink / 2 > 0)
max = (currentPage + TotalNoLink / 2 - (TotalNoLink - 1) % 2);
else
max = TotalNoLink;
if (max > totalPages) max = totalPages;
min = max - TotalNoLink + 1 > 0 ? max - TotalNoLink + 1 : 1;
}
for (int n = min; n <= max; n++)
{
if (n > totalPages)
break;
if (n == currentPage)
strPager.Append(String.Format(" {0}", n.ToString()));
else
strPager.Append(String.Format("{0} ", n, (n - 1) + 1,pageUrl));
}
if (currentPage < totalPages)
strPager.Append(String.Format("Next ", currentPage+1,pageUrl));
return strPager.ToString();
}
}

Wednesday, August 3, 2011

load image or captcha image using jquery and asp.net

Demo for show image or catptch image on button click using jquery........


<script src="jquery-1.6.1.min.js" type="text/javascript"></script>
<script language="javascript" >
$(document).ready(function () {
$("#btnload").click(function () {
$.get("data.ashx", function (data) {

$("#imgload").attr("src",data);
});

});
});
</script>

<img id="imgload" border="0" src="" /> <br />
<button id="btnload">Load Image</button>



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

using System;
using System.Drawing;
using System.Web;
using System.Drawing.Imaging;
using System.IO;
public class data : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Bitmap bmp = new Bitmap(context.Server.MapPath("download.jpg"));
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
bmp.Save(ms, ImageFormat.Jpeg);
byte[] imageBytes = ms.ToArray();

// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
context.Response.Write("data:image/gif;base64," + base64String);
context.Response.End();
}
}

public bool IsReusable
{
get
{
return false;
}
}
}

Wednesday, April 6, 2011

Sending Mail using CDOSYS

<%
dim returnCode
SendMail
if returnCode = True then
'Put your code when mail send successfull
else
'Put your code when mail could not send end if
sub SendMail()
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Send test Mail using CDOSYS"
myMail.From="name@yourdomain.com"
myMail.To="name@yourdomain.com"    'You can also use comma separated Mail
myMail.HTMLBody="Hi

How r you.

Test mail sending Program

" myMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 'Name or IP of remote SMTP server myMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost" 'Server port myMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 myMail.Configuration.Fields.UpdateOn Error Resume Next myMail.Send If Err.Number = 0 then returnCode=True Else returnCode=False End If set myMail=nothing end sub %>
AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath