Monday, November 22, 2010

Regular expression to allow numbers between 1 and 100

Here it is:

^([1-9]|[1-9]\d|100)$

If you dont need 100 in range then expression will be this:

^([1-9]|[1-9]\d)$

Thursday, November 11, 2010

Regular expression for validating Date format dd/MM/yyyy

Hi

Use this following Regular Expression Details, This will support leap year also.

^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$


Matches
[29/02/2000], [30/04/2003], [01/01/2003]

Non-Matches
[29/02/2001], [30-04-2003], [1/1/1899]

Wednesday, November 10, 2010

Regular Expression for Email ID

Regular Expression for Email ID

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Sunday, November 7, 2010

Page index changing in gridview

in gridview1_pageindexchanging(......)
{
gridview1.pageindex=e.newpageindex;
fillgrid();
}

Wednesday, November 3, 2010

Login Page Crawling & Indexing by Search Engines - Solution

Please insert below tag in all login pages to make our site more SEO friendly


META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

Tuesday, November 2, 2010

Ajax Pop up message

Use the following code for the pop up message.

aspx

asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="True" />

asp:Panel ID="Panel1" runat="server">

asp:UpdatePanel id="UpdatePanel2" runat="server">

ContentTemplate>





/ContentTemplate>

/asp:UpdatePanel>

/asp:Panel>

aspx.cs

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Thanks for contacting DGP CONTRACTING.');", true);

ItemCommand events not firing for datalist

Here is a very famous issue which almost every developer goes through: assume we have a databound control like a DataList/DataGrid with a nested Button inside it. We want to handle the Button's click event in our code. We can easily to so using OnItemCommand method which raises ItemCommand event. We need to attach an event handler to this in our code.

The problem crops up when we tyr to bind data on every postback, like:

page_load()
{
//..code//
BindDataControl();
}

Now, when the button control is clicked in the datalist/datagrid, it submits the form causing a postback. In the page_load the databind occurs again and all the information about any attached event handlers is lost as the control is bounded again which means that the nested button control will be re-created. This will cause the ItemCommand event handler not to fire.

Simple solution to this problem is to avoid re-binding of data on postback. For e.g.:

page_load()
{
//..code//
if(!IsPostBack)
{
BindDataControl();
}
}

This will make sure that nested controls are not re-created each time on postback and their "state" is maintained. This makes sure that the ItemCommand event handler is fired when ever the Button control is clicked.