Thursday, October 23, 2008


I am using a great Asp.Net CAPTCHA by BrainJar in a number of web sites with and without Asp.Net AJAX. It’s a simple and really easy to use Asp.Net CAPTCHA. The actual source code is in C#, but you can use it with both C# and VB.Net by simply wrapping the functionality in a class library.

In Asp.Net forums and in many other user communities I have seen lot of people asking for VB.Net CAPTCHA. So I thought to write a blog post and create some sample implementations. The zip file contains C# CAPTCHA and VB.Net CAPTCHA. I have included the samples for Asp.Net AJAX CAPTCHA also.

You can download the samples and implementation from here

Implementing Asp.Net AJAX CAPTCHA is really simple. Just wrap the main Asp.Net CAPTCHA with Asp.Net AJAX update panel and put a random query string at the end of CAPTCHA image src. The random query string will avoid showing the old CAPTCHA from browser cache.

  1. Refer the assembly CaptchaDLL.dll in your project
  2. Copy JpegImage_CS.aspx or JpegImage_VB.aspx (according to the language of choice) to your website.
  3. Open the above file and make changes in Colors and Font if needed. (read the inline comments to know more)
  4. Now user the sample codes from Default.aspx or Ajax.aspx pages. The code is straight forward. You make a session and generate an image with the string in the Session. Now when you submit you have to check the session value and textbox value to see whether the entered CAPTCHA is correct.

If you have any questions please put as a comment.

Asp.Net CAPTCHA, CAPTCHA, VB.Net CAPTCHA, C# CAPTCHA, ASP CAPTCHA, C sharp captcha, vb captcha, simple captcha, AJAX CAPTCHA, ajax captcha, captcha without refresh, captcha using ajax, numeric captcha

Wednesday, October 22, 2008

Numeric Datalist/Repeater paging - User control version

I have wrapped the functionality of numeric datalist pagination (read the full details here) into a user control, so that you don’t need to copy and paste the code in all the pages.
The usercontrol and sample implementation with some good pagination style can be downloaded from here.


Visit this blog if you want to know the details about implementing numeric paging with datalist or repeater.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you are looking for Sql Express DTS/Data transfer wizard click here
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

datalist pagination,paginating datalist,pagination datalist, datalist pagination,datalist and pagination,c# datalist pagination,pages datalist,paging datalist,datalist paging,repeater pagination,paginating repeater,pagination repeater, repeater pagination,repeater and pagination,c# repeater pagination,pages repeater,paging repeater,repeater paging

Friday, October 10, 2008

Simple Numeric Pagination for DataList and Repeater

There are a big number of tutorials available on how to implement pagination in DataList and Repeater. But all of them are explaining only about the Next/Prev mode of pagination only. Recently I have implemented a quick and dirty numeric pagination on DataList for one of my project.

The idea is simply use a PagedDataSource to get the current page of data and bind it to DataList or Repeater. Now create dynamic Linkbuttons using the PageSize and the Total rows count. See the code below.


<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.pagination a{padding:5px;}
.pagination span{padding:5px;}
<form id="form1" runat="server">
<asp:DataList ID="dlPaginationSample" runat="server">
<%# Eval("Column1")%> | <%# Eval("Column2")%>
<br />

<br />
<asp:Panel runat="server" id="pnlPager" CssClass="pagination">


C# Code
//you can pass either DatList or Repeater to this function
private void bindDataWithPaging(Control bindControl, DataSet data)
if (data.Tables.Count > 0) // if the datset contains data
DataView dv = data.Tables[0].DefaultView;

PagedDataSource dsP = new PagedDataSource();
dsP.AllowPaging = true;
dsP.DataSource = dv;
dsP.CurrentPageIndex = CurrentPageIndex;
dsP.PageSize = PageSize;

//Binding data to the controls
if (bindControl is DataList)
((DataList)bindControl).DataSource= dsP;
else if (bindControl is Repeater)
((Repeater)bindControl).DataSource = dsP;

//saving the total page count in Viewstate for later use
PageCount = dsP.PageCount;

//create the linkbuttons for pagination

The above function is straight forward and self explanatory. What it will do is simply create a PagedDataSource from the full dataset and bind it to the custom pagination repeater or datalist.

//create the linkbuttons for pagination
protected void BuildPagination()
pnlPager.Controls.Clear(); //

if (PageCount <= 1) return; // at least two pages should be there to show the pagination

//finding the first linkbutton to be shown in the current display
int start = CurrentPageIndex - (CurrentPageIndex % ButtonsCount);

//finding the last linkbutton to be shown in the current display
int end = CurrentPageIndex + (ButtonsCount - (CurrentPageIndex % ButtonsCount));

//if the start button is more than the number of buttons. If the start button is 11 we have to show the <<First link
if (start > ButtonsCount - 1)
pnlPager.Controls.Add(createButton(FirstPageText, 0));
pnlPager.Controls.Add(createButton("..", start - 1));

int i = 0, j = 0;

for (i = start; i < end; i++)
LinkButton lnk;
if (i < PageCount)
if (i == CurrentPageIndex) //if its the current page
Label lbl = new Label();
lbl.Text = (i + 1).ToString();
pnlPager.Controls.Add(createButton((i + 1).ToString(), i));

//If the total number of pages are greaer than the end page we have to show Last>> link
if (PageCount > end)
pnlPager.Controls.Add(createButton("..", i));
pnlPager.Controls.Add(createButton(">>", PageCount - 1));

This is the whole logic for a simple implementation. I am using this custom pagination in a number of projects and they are working great.

DOWNLOAD THE SOURCE AND SAMPLES FROM HERE for numeric datalist pagination

Implement custom numeric pagination with datalist and repeater, Datalist pagination, repeater pagination, paginating datalist, paginating repeater, numeric custom pagination, custom datalist pagination, custom repeater pagination, repeater numeric pagination, datalist numeric pagination, pagination with datalist and repeater, implement pagination datalist, datalist pagination

Wednesday, October 8, 2008

Move to anchor after ASP.Net AJAX postback

Here is the code to move to anchor after postback

<script language="javascript" type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
function OnEndRequest(sender,args)
window.location.hash = '#MOVEHERE'; //MOVEHERE is the anchor name

If you want to show top of the page instead of move to anchor use window.scrollTo(0,0); instead of window.location.hash = '#MOVEHERE';