Archive

Archive for December, 2009

Get Current Page Name In Asp.net, C# codebehind

December 28, 2009 1 comment

Below method will give current page name in C#, asp.net 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;
}

Asp.net Ajax Calendar Extender and Past Date Validation Javascript

December 23, 2009 5 comments

When using asp.net 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”);

}

}

</script>

<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”>

</cc1:CalendarExtender>

Generate Serial Number in Gridview in Asp.net

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”>
 <Columns>
 <asp:TemplateField>
 <ItemTemplate>
 <%#Container.DataItemIndex+1 %>
 </ItemTemplate>
 </asp:TemplateField>
</Columns>
 </asp:GridView>

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..

http://www.mostinspired.com/blog/2008/10/11/admin-templates/

http://www.webresourcesdepot.com/free-admin-template-for-web-applications/

http://www.bloganje.com/free-admin-template.html

There are also some paid templates:

http://www.webappers.com/2009/09/18/20-professional-web-admin-templates-on-themeforest/

Open Asp.net Application in Fullscreen using javascript

December 10, 2009 1 comment

Sometimes, we may have a requirement to open the asp.net 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 window.open and its fullscreen properties to open home page as follows:

StringBuilder popupScript = new StringBuilder();

popupScript.Append(“<script language=’JavaScript’> window.name = ‘windowname’;open(”, ‘windowname’); window.close();window.open(‘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 window.open 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?