Archive for December, 2009

Get Current Page Name In, C# codebehind

December 28, 2009 1 comment

Below method will give current page name in C#, Code behind:

/// <summary>
/// Pankaj lalwani
/// GetCurrentPageName
/// </summary>
/// <returns>Current Page name</returns>
public static string GetCurrentPageName()
string sPath = HttpContext.Current.Request.Url.AbsolutePath;
string[] strarry = sPath.Split(‘/’);
int lengh = strarry.Length;
string sRet = strarry[lengh – 1];
return sRet;

Advertisements Ajax Calendar Extender and Past Date Validation Javascript

December 23, 2009 5 comments

When using ajax calendar extender, we want to restrict users from selecting dates in the past.So to achieve that we have to make use of OnClientDateSelectionChanged  event of calendarextender.Below is the code.

<script language=”javascript” type=”text/javascript”>

function CheckForPastDate(sender, args) {

var selectedDate = new Date();

selectedDate = sender._selectedDate;

var todayDate = new Date();

if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {

sender._selectedDate = todayDate;                  sender._textbox.set_Value(sender._selectedDate.format(sender._format));

alert(“Date Cannot be in the past”);




<asp:TextBox ID=”txtDate” contentEditable=”false” runat=”server” CssClass=”txtcss”></asp:TextBox>&nbsp;

<asp:Image ID=”imgCal” runat=”server” ImageUrl=”~/img/calendar.gif” />

<cc1:CalendarExtender ID=”CalExtDate” runat=”server” FirstDayOfWeek=”Sunday” PopupButtonID=”imgCal”PopupPosition=”BottomLeft” Format=”dd/MM/yyyy” OnClientDateSelectionChanged=”CheckForPastDate” TargetControlID=”txtDate”>


Generate Serial Number in Gridview in

December 15, 2009 3 comments

Many times we need to keep serial number in grid view as the first column, most of us get it through select query in stored procedure by making use of ROW_NUMBER() OVER (ORDER BY fieldname) but we can do the same thing in the aspx page where gridview is placed like this.

<asp:GridView  runat=”server” id=”gvDemo”>
 <%#Container.DataItemIndex+1 %>

Free Admin Templates For Web Applications

December 12, 2009 2 comments

Most of us, developers somewhere lack in designing, we may be perfect in giving functionality by development, but we lack in good user interface.

Here is a solution to that problem, use predefined templates for your websites, when you are developing CMS or any other Admin module.. etc..

You can download free templates, and integrate it your project from below..

There are also some paid templates:

Open Application in Fullscreen using javascript

December 10, 2009 1 comment

Sometimes, we may have a requirement to open the application developed, to be opened in full screen mode. To accomplish this, below is the code, in login page, after verifying credentials we redirect user to home page.

So now using javascript, we have to use and its fullscreen properties to open home page as follows:

StringBuilder popupScript = new StringBuilder();

popupScript.Append(“<script language=’JavaScript’> = ‘windowname’;open(”, ‘windowname’); window.close();‘home.aspx’, ”, ‘fullscreen=yes,status=yes,scrollbars=yes,titlebar=no,addressbar=no’);</script>”);

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), “PopupScript”, popupScript.ToString(), false);

On Logout, you can write the same script with fullscreen = no

Above code will also bypass the alert message we are getting when redirecting to another page using in javascript.

It will by pass the message prompted

“The Web page you are viewing is trying to close the window” Do you want to close this window?