Monday, May 28, 2012

Operation is not valid due to the current state of the object. :ASP.Net Error

Issue:
System.InvalidOperationExceptionOperation is not valid due to the current state of the object.
    System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.get_Form()
   at Rhino.Commons.LongConversationManager.LoadConversationFromRequest(Boolean& privateConversation)
   at Rhino.Commons.LongConversationManager.LoadConversation()
   at Rhino.Commons.HttpModules.UnitOfWorkApplication.UnitOfWorkApplication_BeginRequest(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 
Cause:

Microsoft recently (12-29-2011) released an update to address several serious security vulnerabilities in the .NET Framework. MS11-100 was introduced just recently that handles potential DoS attacks.

Unfortunately the fix has also broken page POSTs with very large amounts of posted data (form fields). MS11-100 places a limit of 500 on postback items. The new default max introduced by the recent security update is 1000.

Adding the setting key to the web-config file overcomes this limitation, as in this example increases it to 2000.

  <appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2000" />
</appSettings>

Saturday, May 26, 2012

ASP.Net Page Life Cycle

When a page request is sent to the Web server, the page is run through a series of events during its creation and disposal. In this article, I will discuss in detail the ASP.NET page life cycle Events
(1) PreInit The entry point of the page life cycle is the pre-initialization phase called “PreInit”. This is the only event where programmatic access to master pages and themes is allowed. You can dynamically set the values of master pages and themes in this event. You can also dynamically create controls in this event.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;using 
System.Web.UI;
using System.Web.UI.WebControls; 

public partial class _Default : System.Web.UI.Page
{    
    protected void Page_PreInit(object sender, EventArgs e)    
    {       
      //  Use this event for the following:         
      //  Check the IsPostBack property to determine whether this is the first time the page is being processed.       
      //  Create or re-create dynamic controls.        
      //  Set a master page dynamically.        
      //  Set the Theme property dynamically.           
    }  
  


(2)Init This event fires after each control has been initialized, each control's UniqueID is set and any skin settings have been applied. You can use this event to change initialization values for controls. The “Init” event is fired first for the most bottom control in the hierarchy, and then fired up the hierarchy until it is fired for the page itself.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected void Page_Init(object sender, EventArgs e)
{
   // Raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.
}


(3)InitComplete Raised once all initializations of the page and its controls have been completed. Till now the viewstate values are not yet loaded, hence you can use this event to make changes to view state that you want to make sure are persisted after the next postback
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected void Page_InitComplete(object sender, EventArgs e)

{       
   // Raised by the  Page object. Use this event for processing tasks that require all initialization be complete.
 }



(4)PreLoad Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance
(1)Loads ViewState : ViewState data are loaded to controls Note : The page viewstate is managed by ASP.NET and is used to persist information over a page roundtrip to the server. Viewstate information is saved as a string of name/value pairs and contains information such as control text or value. The viewstate is held in the value property of a hidden <input> control that is passed from page request to page request.
(2)Loads Postback data : postback data are now handed to the page controls Note : During this phase of the page creation, form data that was posted to the server (termed postback data in ASP.NET) is processed against each control that requires it. Hence, the page fires the LoadPostData event and parses through the page to find each control and updates the control state with the correct postback data. ASP.NET updates the correct control by matching the control's unique ID with the name/value pair in the NameValueCollection. This is one reason that ASP.NET requires unique IDs for each control on any given page.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected override void OnPreLoad(EventArgs e)

{        
      // Use this event if you need to perform processing on your page or control before the  Load event.        
      // Before the Page instance raises this event, it loads view state for itself and all controls, 
      and then processes any postback data included with the Request instance.
 }



(5)Load The important thing to note about this event is the fact that by now, the page has been restored to its previous state in case of postbacks. Code inside the page load event typically checks for PostBack and then sets control properties appropriately. This method is typically used for most code, since this is the first place in the page lifecycle that all values are restored. Most code checks the value of IsPostBack to avoid unnecessarily resetting state. You may also wish to call Validate and check the value of IsValid in this method. You can also create dynamic controls in this method.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected void Page_Load(object sender, EventArgs e)

{        
         // The  Page calls the  OnLoad event method on the  Page, then recursively does the same for each child control, 
         which does the same for each of its child controls until the page and all controls are loaded.      
        // Use the OnLoad event method to set properties in controls and establish database connections.
 }


(6)Control (PostBack) event(s)ASP.NET now calls any events on the page or its controls that caused the PostBack to occur. This might be a button’s click event or a dropdown's selectedindexchange event, for example.These are the events, the code for which is written in your code-behind class(.cs file).
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected void Button1_Click(object sender, EventArgs e)

{        // This is just an example of control event.. Here it is button click event that caused the postback}



(7)LoadComplete This event signals the end of Load.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected void Page_LoadComplete(object sender, EventArgs e)

{        // Use this event for tasks that require that all other controls on the page be loaded.}



(8)PreRender Allows final changes to the page or its control. This event takes place after all regular PostBack events have taken place. This event takes place before saving ViewState, so any changes made here are saved.
For example : After this event, you cannot change any property of a button or change any viewstate value. Because, after this event, SaveStateComplete and Render events are called.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected override void OnPreRender(EventArgs e)

{        
         // Each data bound control whose DataSourceID property is set calls its DataBind method.       
         // The PreRender event occurs for each control on the page. Use the event to make final changes to the contents of the page or its controls.
 }



(9)SaveStateComplete Prior to this event the view state for the page and its controls is set. Any changes to the page’s controls at this point or beyond are ignored.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
protected override void OnSaveStateComplete(EventArgs e)
{       
     // Before this event occurs,  ViewState has been saved for the page and for all controls. Any changes to the page or controls at this point will be ignored.        // Use this event perform tasks that require view state to be saved, but that do not make any changes to controls.
}


(10)Render This is a method of the page object and its controls (and not an event). At this point, ASP.NET calls this method on each of the page’s controls to get its output. The Render method generates the client-side HTML, Dynamic Hypertext Markup Language (DHTML), and script that are necessary to properly display a control at the browser. Note: Right click on the web page displayed at client's browser and view the Page's Source. You will not find any aspx server control in the code. Because all aspx controls are converted to their respective HTML representation. Browser is capable of displaying HTML and client side scripts.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page


(11) UnLoad This event is used for cleanup code. After the page's HTML is rendered, the objects are disposed of. During this event, you should destroy any objects or references you have created in building the page. At this point, all processing has occurred and it is safe to dispose of any remaining objects, including the Page object. Cleanup can be performed on-
(a)Instances of classes i.e. objects
(b)Closing opened files
(c)Closing database connections.
EXAMPLE : Override the event as given below in your code-behind cs file of your aspx page
        protected void Page_UnLoad(object sender, EventArgs e)  
        {       
            // This event occurs for each control and then for the page. In controls, 
            use this event to do final cleanup for specific controls, such as closing control-specific database connections.       
            // During the unload stage, the page and its controls have been rendered, so you cannot make further changes to the response stream.          
            //If you attempt to call a method such as the Response.Write method, the page will throw an exception.   
       }



For More Reference : Follow the below links
(1)http://www.15seconds.com/issue/020102.htm
(2) http://msdn.microsoft.com/en-us/library/ms178472.aspx
(3) http://www.devlifestyle.net/blogs/articles/archive/2009/05/24/asp-net-internals-viewstate-and-page-life-cycle.aspx

Thank You...

Tuesday, May 15, 2012

ASP.Net Custom Pager

Create simple ASP.Net custom pager for List View, Grid View,etc. with SQL paging.




Create a user control for Paging and add to main page
<%@ Register Src="~/SysControls/SysAdminPager.ascx" TagName="DataPagerControl" TagPrefix="uc1" %>
.
.
.
 

Using a simple list view for binding data.
<uc1:DataPagerControl ID="sysPager" runat="server" />
        <asp:ListView ID="lstView" runat="server">
            <LayoutTemplate>
                <table class="normal fullwidth">
                    <thead>
                        <tr style="background-color: #EEE">
                            <th>
                                ID
                            </th>
                            <th>
                                Name
                            </th>
                            <th>
                                Address
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
                    </tbody>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr class='<%# (Container.DataItemIndex+1)%2==0?"":"odd" %>'>
                    <td>
                        <%#Eval("ID") %>
                    </td>
                    <td>
.
.
.


On Page Load Reginster Event handler for Pager Control. Use Sql Paging..pass your page number and page size SP and return data and totalrow count . Set page properties using pagenumber,pagesize and total rows
  
  protected void Page_Load(object sender, EventArgs e)
        {
            sysPager.PageChanged += new EventHandler<PageEventArgs>(sysPager_PageChanged);
            if (!IsPostBack)
            {
                BindData();
            }
        }
        void sysPager_PageChanged(object sender, PageEventArgs e)
        {
            BindData(e.StartRowIndex, e.MaximumRows);
        }
        void BindData(int pagenumber = 1, int pagesize = 20)
        {
            SampleCollectionML lstCollection = SampleBL.SelectAll(new SampleML { PageNumber = pagenumber, PageSize = pagesize });
            if (lstCollection.Count > 0)
            {
                lstView.DataSource = lstCollection;
                lstView.DataBind();
                sysPager.SetPageProperties(pagenumber, pagesize, lstCollection[0].TotalRows);
            }
        } 


Source code User Control For Pager
  <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SysAdminPager.ascx.cs"
    Inherits=" GradeBook.SysControls.SysAdminPager" %>
<div class="pager-container">
    <div style="float: left; margin-right: 15px; vertical-align: middle">
        Page size:
        <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged"
            Style="padding: 2px;">
            <asp:ListItem Value="10" Text="10"></asp:ListItem>
            <asp:ListItem Value="20" Text="20"></asp:ListItem>
            <asp:ListItem Value="50" Text="50"></asp:ListItem>
            <asp:ListItem Value="100" Text="100"></asp:ListItem>           
        </asp:DropDownList>
    </div>
    <asp:Repeater ID="rpt" runat="server">
        <HeaderTemplate>
            <div class='<%# PagerCss %>'>
                <div style="float: left; padding: 4px 0 2px;">
                    Page <b>
                        <%# Convert.ToInt32(TotalRowCount > 0 ? CurrentPage : 0)%>                       
                    </b>of <b>
                        <%# Convert.ToInt32(MaximumRows>0? Math.Ceiling((double)TotalRowCount / MaximumRows):0)%>
                    </b>(<%# TotalRowCount %>
                    item(s))
                </div>
                <div style="float: right; padding-top: 2px;">
                    <asp:LinkButton ID="lnkbFirst" CommandName="<%#PageChangedItemCommand %>" CommandArgument="1"
                        runat="server" ToolTip="First" CssClass="page-text">&laquo;First</asp:LinkButton>&nbsp;
                    <asp:LinkButton ID="lnkbPrevious" CommandName="<%#PageChangedItemCommand %>" CommandArgument="<%#PreviousPageIndex%>"
                        runat="server" ToolTip="Previous" CssClass="page-text">&laquo;Prev</asp:LinkButton>
            &nbsp;
        </HeaderTemplate>
        <ItemTemplate>
            <asp:LinkButton CommandName="<%#PageChangedItemCommand %>" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "Page")%>'
                ID="p" runat="server"><%#DataBinder.Eval(Container.DataItem, "Text")%>&nbsp;</asp:LinkButton>
        </ItemTemplate>
        <FooterTemplate>
            <asp:LinkButton ID="lnkbNext" CommandName='<%#PageChangedItemCommand %>' CommandArgument="<%#NextPageIndex%>"
                runat="server" ToolTip="Next" CssClass="page-text">Next &raquo;</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="lnkbLast" CommandName="<%#PageChangedItemCommand %>" CommandArgument="<%#PagesCount%>"
                runat="server" ToolTip="Last" CssClass="page-text">Last &raquo;</asp:LinkButton>
            </div> </div>
        </FooterTemplate>
    </asp:Repeater>
    <div style="float: right; margin-right: 6px">
        Go to:
        <asp:DropDownList ID="ddlPageNumber" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPageNumber_SelectedIndexChanged"
            Style="padding: 2px;">
        </asp:DropDownList>
    </div>
    <div class="clear">
    </div>
</div>




A Class for holding Paging parameter
  public class SysPager
    {
        public int Page { get; set; }
        public string Text { get; set; }
        public SysPager(int _p, string _t)
        {
            Page = _p;
            Text = _t;
        }
    }


Page Propeties for holding paging information
        //public partial class SysAdminPager : System.Web.UI.UserControl
        // {
        // Summary:
        //     Gets the maximum number of records to display on each page.
        //
        // Returns:
        //     The maximum number of records to display on each page.
        public int MaximumRows
        {
            get
            {
                return (int)(ViewState["MaximumRows"] ?? 10);
            }
            set
            {
                ViewState["MaximumRows"] = value;
            }
        }
        //
        // Summary:
        //     Gets the index of the first record on a page.
        //
        // Returns:
        //     The index of the first record on a page.
        public int CurrentPage
        {
            get
            {
                return (int)(ViewState["CurrentPage"] ?? 1);
            }
            set
            {
                ViewState["CurrentPage"] = value;
            }
        }
        //
        // Summary:
        //     Gets the total number of records in the underlying data source.
        //
        // Returns:
        //     The total number of records of the underlying data source.
        public int TotalRowCount
        {
            get
            {
                return (int)(ViewState["TotalRowCount"] ?? 0);
            }
            set
            {
                ViewState["TotalRowCount"] = value;
            }
        }

        public int ButtonCount
        {
            get
            {
                return (int)(ViewState["ButtonCount"] ?? 10);
            }
            set
            {
                ViewState["ButtonCount"] = value;
            }
        }

        private int _pagesCount;

        public int PagesCount
        {
            get
            {
                if (TotalRowCount == 0)
                    return _pagesCount = 0;
                else if (TotalRowCount % MaximumRows == 0)
                    return _pagesCount = (TotalRowCount / MaximumRows);
                else
                    return _pagesCount = ((TotalRowCount / MaximumRows) + 1);
            }

            private set
            {
                _pagesCount = value;
            }
        }

        public string PagerCss
        {
            get
            {
                return (string)(ViewState["PagerCss"] ?? "pagination-default");
            }
            set
            {
                ViewState["PagerCss"] = value;
            }
        }
        protected int NextPageIndex { get { return CurrentPage + 1; } }
        protected int PreviousPageIndex { get { return CurrentPage - 1; } }


Page Changing Event Declaration and Invoking
        public event EventHandler<PageEventArgs> PageChanged;
        protected const string PageChangedItemCommand = "PageChanged";
        private const string CurrentPageCssStyle = "current";//"font-weight:bold; font-size:15px;";

        private void RaiseEvent(int currentPage)
        {
            if (PageChanged != null)
                PageChanged(this, new PageEventArgs(currentPage, MaximumRows, TotalRowCount));
        }


Create Paging data using Totalrows,Pagesize and button count
       
     protected List<SysPager> DataSource
        {
            get
            {
                List<SysPager> pages = new List<SysPager>();
                int _startpage = 1;
                int _endpage = PagesCount;
                bool showMore_first = false;
                bool showMore_last = false;
                if (PagesCount > ButtonCount)
                {
                    if (CurrentPage - (ButtonCount / 2) > 1)
                    {
                        _startpage = CurrentPage - (ButtonCount / 2);
                        showMore_first = true;
                    }
                    if (CurrentPage + (ButtonCount / 2) < PagesCount)
                    {
                        _endpage = CurrentPage + (ButtonCount / 2);
                        if (_endpage < ButtonCount)
                            _endpage = ButtonCount;

                        showMore_last = true;
                    }
                }
                if (showMore_first)
                {
                    pages.Add(new SysPager(_startpage - 1, "..."));
                }
                for (int i = _startpage; i <= _endpage; i++)
                {

                    pages.Add(new SysPager(i, i.ToString()));
                }
                if (showMore_last)
                {
                    pages.Add(new SysPager(_endpage + 1, "..."));

                }

                return pages;
            }
        }



        public SysAdminPager()
        {
            CurrentPage = 1;
            MaximumRows = 1;
            TotalRowCount = 1;
        }



Page Load And Other Events
        protected void Page_Load(object sender, EventArgs e)
        {
            rpt.ItemCommand += new RepeaterCommandEventHandler(rpt_ItemCommand);

            if (!Page.IsPostBack)
            {
                //CurrentPageSetCssStyle(CurrentPageCssStyle);
                // SetupCommandArguments();
            }
        }

        void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == PageChangedItemCommand)
            {
                CurrentPage = int.Parse(e.CommandArgument.ToString());
                CurrentPageSetCssStyle(CurrentPageCssStyle);
                // SetupCommandArguments();
                SetPageProperties();
                RaiseEvent(CurrentPage);

            }
        }



        private void CurrentPageSetCssStyle(string style)
        {
            ddlPageNumber.SetDropDownSelectedValue(CurrentPage);
            ddlPageSize.SetDropDownSelectedValue(MaximumRows);
            foreach (RepeaterItem item in rpt.Items)
            {
                LinkButton lnkButton = item.FindControl("p") as LinkButton;
                if (lnkButton != null)
                {
                    if (lnkButton.CommandArgument == CurrentPage.ToString())
                        lnkButton.Attributes.Add("class", style);
                }
            }
            //  SetupCommandArguments();
        }



        void SetupCommandArguments()
        {
            LinkButton lnkbPrevious = rpt.Controls[0].Controls[0].FindControl("lnkbPrevious") as LinkButton;
            LinkButton lnkbFirst = rpt.Controls[0].Controls[0].FindControl("lnkbFirst") as LinkButton;
            if (lnkbPrevious != null)
            {

                if (CurrentPage == 1 || PagesCount == 0)
                {
                    lnkbPrevious.Enabled = false;
                    lnkbFirst.Enabled = false;
                    lnkbPrevious.CommandArgument = (CurrentPage).ToString();
                }
                else
                {
                    lnkbPrevious.Enabled = true;
                    lnkbFirst.Enabled = true;
                    lnkbPrevious.CommandArgument = (CurrentPage - 1).ToString();
                }
            }

            LinkButton lnkbNext = rpt.Controls[rpt.Controls.Count - 1].Controls[0].FindControl("lnkbNext") as LinkButton;
            LinkButton lnkbLast = rpt.Controls[rpt.Controls.Count - 1].Controls[0].FindControl("lnkbLast") as LinkButton;
            if (lnkbNext != null)
            {
                if (CurrentPage == PagesCount || PagesCount == 0)
                {
                    lnkbNext.CommandArgument = (CurrentPage).ToString();
                    lnkbNext.Enabled = false;
                    lnkbLast.Enabled = false;
                }
                else
                {
                    lnkbNext.CommandArgument = (CurrentPage + 1).ToString();
                    lnkbNext.Enabled = true;
                    lnkbLast.Enabled = true;
                }
            }
        }

        internal void SetPageProperties(int _startpage, int _maxrows, int _totrows)
        {
            CurrentPage = _startpage;
            MaximumRows = _maxrows;
            TotalRowCount = _totrows;

            SetPageProperties();
        }
        internal void SetPageProperties()
        {

            rpt.DataSource = DataSource;
            rpt.DataBind();
            SetupCommandArguments();

            ddlPageNumber.Items.Clear();
            for (int i = 1; i <= PagesCount; i++)
            {
                ddlPageNumber.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
            CurrentPageSetCssStyle(CurrentPageCssStyle);



        }



Dropdown LIst Changing Events
       
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {

                MaximumRows = int.Parse(ddlPageSize.SelectedValue);
                if (PagesCount < CurrentPage)
                    CurrentPage = PagesCount;
                CurrentPageSetCssStyle(CurrentPageCssStyle);
                SetPageProperties();
                RaiseEvent(CurrentPage);
            }
            catch (Exception)
            {

            }

        }
        protected void ddlPageNumber_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                CurrentPage = int.Parse(ddlPageNumber.SelectedValue);
                CurrentPageSetCssStyle(CurrentPageCssStyle);
                SetPageProperties();
                RaiseEvent(CurrentPage);
            }
            catch (Exception)
            {

            }

        }
       
    }



You can change theme Gray,Blue,Red,Green.
 /*########################################################  Pagination  ########################################################*/
.pager-container {
    background: -moz-linear-gradient(center top , #FBFBFB, #F5F5F5) repeat scroll 0 0 transparent;
    border: 1px solid #CBC5C5;
    border-radius: 5px 5px 5px 5px;
    padding: 5px 8px;
}
.pagination a{font-size: 9px !important;text-transform: uppercase; /* background-color: #FFFFFF;*/border: 1px #5e90c3 solid;color: #5e90c3;padding: 1px 3px;
               text-decoration: none;outline: none;}
.pagination a:hover{    color: white;background-color: #5e90c3;border: 1px #5e90c3 solid;}
.pagination a.current,.pagination a:hover{font-size: 9px;text-transform: uppercase;background-color: #5e90c3;
                                          border: 1px solid #F2F2F2;color: white;padding: 1px 5px;text-decoration: none;outline: none;}
.pagination a[disabled=disabled]{    background-color: #CCCCCC;border: 1px solid #F2F2F2;color: #003366;}

/* $$$$$$$$$$$$$$  Default $$$$$$$$$$$$$$$$*/  
.pagination-default a{
   font-size: 10px !important;text-transform: uppercase;color: #606060;border: 1px solid #DDDDDD;border-radius: 4px;
   padding: 2px 3px; cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;   
  
   /*border-color: #c0c0c0 #d4d4d4 #dbdbdb;text-shadow: 0px -1px 0px #fff;
   background: -moz-linear-gradient(top,#ebebeb,#f4f4f4 50%,#fff); background: -webkit-gradient(linear, left top, left bottom, from(#ebebeb), color-stop(0.5, #f4f4f4),to(#fff));
 filter: progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#f4f4f4', EndColorStr='#ffffff');*/ } 
 
   .pagination-default a.current,.pagination-default a:hover {  color: #606060; text-shadow: 0px 1px 0px #fff;                                                         
                                                           border-color: #D0D0D0; box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);}
  
  .pagination-default a:hover{  background: #f1f1f1;}                                                         
   .pagination-default a.current{ box-shadow:none; background-color: #e0e0e0; background: -moz-linear-gradient(top,#e0e0e0,#f4f4f4 50%,#e0e0e0)); 
                                                          background: -webkit-gradient(linear, left top, left bottom,from(#fff),color-stop(0.5, #f4f4f4),to(#e0e0e0));
                                                          filter: progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#f4f4f4', EndColorStr='#e0e0e0');}                                                                                                                    
  .pagination-default a[disabled=disabled]{  color: #aaa;}
  .pagination-default a.page-text{border:none;text-decoration:underline;}
 
/* $$$$$$$$$$$$$$  ORANGE $$$$$$$$$$$$$$$$*/  
 /* $$$$$$$$$$$$$$  GRAY $$$$$$$$$$$$$$$$*/
.pagination-gray a{ font-size: 9px !important;text-transform: uppercase; border: 1px #5e90c3 solid;color: #5e90c3;padding: 1px 3px;
   cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;  -moz-border-radius: 3px;   
    -webkit-border-radius: 3px;    -khtml-border-radius: 3px;    border-radius: 3px;    
    -moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);    -webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);   
     -khtml-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5); 
    background: #f1f1f1;    background: -webkit-gradient(linear, left top, left bottom, from(#e9e9e9), to(#d1d1d1));
    background: -moz-linear-gradient(top,  #e9e9e9,  #d1d1d1);    -pie-background: linear-gradient(top,  #e9e9e9,  #d1d1d1);    
    border: 1px solid #bbb;    color: #555;    text-shadow: 0 1px 0 #fff;
 } 
 .pagination-gray a.current ,.pagination-gray a:hover {       background: #fff;    -pie-background: #fff;    color: #666;}
.pagination-gray a[disabled=disabled]{   color: #aaa;}

 /* $$$$$$$$$$$$$$  WHITE $$$$$$$$$$$$$$$$*/  
.pagination-white a{
   font-size: 9px !important;text-transform: uppercase; /* background-color: #FFFFFF;*/border: 1px #D8D8D8 solid;color: #606060;padding: 1px 3px;
   cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;   
    -moz-border-radius: 3px;    -webkit-border-radius: 3px;    -khtml-border-radius: 3px;    border-radius: 3px;    
    -moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);  -webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);  -khtml-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);       box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);     
     background: #fff;    -pie-background: #fff;        border: 1px solid #bbb;    color: #555;
    text-shadow: 0 1px 0 #fff; } 
 .pagination-white a.current,.pagination-white a:hover { background: #f1f1f1;background: -webkit-gradient(linear, left top, left bottom, from(#e9e9e9), to(#d1d1d1));
                                                            background: -moz-linear-gradient(top,  #e9e9e9,  #d1d1d1);  -pie-background: linear-gradient(top,  #e9e9e9,  #d1d1d1);  
                                                             color: #666;}
.pagination-white a[disabled=disabled]{   color: #aaa;}
 
/* $$$$$$$$$$$$$$  ORANGE $$$$$$$$$$$$$$$$*/  
.pagination-orange a
{
   font-size: 9px !important;text-transform: uppercase; /* background-color: #FFFFFF;*/border: 1px #D8D8D8 solid;color: #606060;padding: 1px 3px;
   cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;   
    -moz-border-radius: 3px;    -webkit-border-radius: 3px;    -khtml-border-radius: 3px;    border-radius: 3px;
    
     background: #f78d1d;
    background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
    background: -moz-linear-gradient(top, #faa51a, #f47a20);
    -pie-background: linear-gradient(top, #faa51a, #f47a20);
    border: solid 1px #dd6611;
    color: #fef4e9;
    text-shadow: 0 1px 1px rgba(0,0,0,0.25);     
 } 
 .pagination-orange a.current,.pagination-orange a:hover { 
     background: #EEEEEE;
    background: -webkit-gradient(linear, left top, left bottom, from(#FFFFFF), to(#EEEEEE));
    background: -moz-linear-gradient(top,  #FFFFFF,  #EEEEEE);
    -pie-background: linear-gradient(top,  #FFFFFF,  #EEEEEE);
    border: solid 1px #F88E11;
    color: #F88E11;
}
.pagination-orange a[disabled=disabled]
{
   color: #d1d1d1;
}
 
/* $$$$$$$$$$$$$$  RED $$$$$$$$$$$$$$$$*/  
.pagination-red a
{
   font-size: 9px !important;text-transform: uppercase; /* background-color: #FFFFFF;*/border: 1px #D8D8D8 solid;color: #606060;padding: 1px 3px;
   cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;   
    -moz-border-radius: 3px;    -webkit-border-radius: 3px;    -khtml-border-radius: 3px;    border-radius: 3px;
    
   background-color: #C44747;
    background: -moz-linear-gradient(top, #DD5F5F 10%, #A92C2C 90%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0.1, #DD5F5F), color-stop(0.9, #A92C2C));
    -pie-background: linear-gradient(top, #DD5F5F 10%, #A92C2C 90%);
    border: 1px solid #A92C2C; 
    color: #fef4e9;
    text-shadow: 0 1px 1px rgba(0,0,0,0.25);
 } 
 .pagination-red a.current,.pagination-red a:hover { 
     background-color: #FFFFFF;
    background: -moz-linear-gradient(top, #FFFFFF  10%, #EEEEEE 90%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0.1, #FFFFFF ), color-stop(0.9, #EEEEEE));
    -pie-background: linear-gradient(top, #FFFFFF  10%, #EEEEEE 90%);
    border: 1px solid #ccc; 
    color: #000;
}
.pagination-red a[disabled=disabled]
{
   color: #CCCCCC;
}
 
/* $$$$$$$$$$$$$$  BLUE $$$$$$$$$$$$$$$$*/  
.pagination-blue a
{
   font-size: 9px !important;text-transform: uppercase; /* background-color: #FFFFFF;*/border: 1px #D8D8D8 solid;color: #606060;padding: 3px 3px;
   cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;   
    -moz-border-radius: 3px;    -webkit-border-radius: 3px;    -khtml-border-radius: 3px;    border-radius: 3px;
    
   background: #0095cd;
    background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
    background: -moz-linear-gradient(top,  #00adee,  #0078a5);
    -pie-background: linear-gradient(top,  #00adee,  #0078a5);
    border: 1px solid #034462;
    color: #fff;
    text-shadow: 0 1px 1px rgba(0,0,0,0.25);
 } 
 .pagination-blue a.current,.pagination-blue a:hover { 
     background: #EEE;
    background: -webkit-gradient(linear, left top, left bottom, from(#EEE), to(#FFF));
    background: -moz-linear-gradient(top,  #EEE,  #FFF);
    -pie-background: linear-gradient(top,  #EEE,  #FFF);
    border: 1px solid #234;
    color: #000;
}
.pagination-blue a[disabled=disabled]{   color: #ccc;}
 
/* $$$$$$$$$$$$$$  GREEN $$$$$$$$$$$$$$$$*/  
.pagination-green a
{
   font-size: 9px !important;text-transform: uppercase; /* background-color: #FFFFFF;*/border: 1px #D8D8D8 solid;color: #606060;padding: 1px 3px;
   cursor: pointer;    outline: none !important;    text-align: center;    text-decoration: none;   
    -moz-border-radius: 3px;    -webkit-border-radius: 3px;    -khtml-border-radius: 3px;    border-radius: 3px;
    
    color: #fff;
    background: #8fc857;
    background: -webkit-gradient(linear, left top, left bottom, from(#8fc857), to(#5c9425));
    background: -moz-linear-gradient(top,  #8fc857,  #5c9425);
    -pie-background: linear-gradient(top,  #8fc857,  #5c9425);
    text-shadow: 0 1px 1px rgba(0,0,0,0.25);
    border:1px solid #561;
 } 
 .pagination-green a.current,.pagination-green a:hover { 
     background: #E9E9E9;
    background: -webkit-gradient(linear, left top, left bottom, from(#E9E9E9), to(#D1D1D1));
    background: -moz-linear-gradient(top,  #E9E9E9,  #D1D1D1);
    -pie-background: linear-gradient(top,  #E9E9E9,  #D1D1D1);
    border:1px solid #342;     
}
.pagination-green a[disabled=disabled]
{
   color: #ccc;
}
 
/* $$$$$$$$$$$$$$  PAGINATIOn END $$$$$$$$$$$$$$$$*/  

DateTime.ToString() Patterns


DateTime.ToString() Patterns


All the patterns:

0 MM/dd/yyyy 08/22/2006
1 dddd, dd MMMM yyyy Tuesday, 22 August 2006
2 dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2006 06:30
3 dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2006 06:30 AM
4 dddd, dd MMMM yyyy H:mm Tuesday, 22 August 2006 6:30
5 dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2006 6:30 AM
6 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07
7 MM/dd/yyyy HH:mm 08/22/2006 06:30
8 MM/dd/yyyy hh:mm tt 08/22/2006 06:30 AM
9 MM/dd/yyyy H:mm 08/22/2006 6:30
10 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
10 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
10 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
11 MM/dd/yyyy HH:mm:ss 08/22/2006 06:30:07
12 MMMM dd August 22
13 MMMM dd August 22
14 yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2006-08-22T06:30:07.7199222-04:00
15 yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2006-08-22T06:30:07.7199222-04:00
16 ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Tue, 22 Aug 2006 06:30:07 GMT
17 ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Tue, 22 Aug 2006 06:30:07 GMT
18 yyyy'-'MM'-'dd'T'HH':'mm':'ss 2006-08-22T06:30:07
19 HH:mm 06:30
20 hh:mm tt 06:30 AM
21 H:mm 6:30
22 h:mm tt 6:30 AM
23 HH:mm:ss 06:30:07
24 yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2006-08-22 06:30:07Z
25 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07
26 yyyy MMMM 2006 August
27 yyyy MMMM 2006 August

The patterns for DateTime.ToString ( 'd' ) :

0 MM/dd/yyyy 08/22/2006

The patterns for DateTime.ToString ( 'D' ) :

0 dddd, dd MMMM yyyy Tuesday, 22 August 2006

The patterns for DateTime.ToString ( 'f' ) :

0 dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2006 06:30
1 dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2006 06:30 AM
2 dddd, dd MMMM yyyy H:mm Tuesday, 22 August 2006 6:30
3 dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2006 6:30 AM

The patterns for DateTime.ToString ( 'F' ) :

0 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07

The patterns for DateTime.ToString ( 'g' ) :

0 MM/dd/yyyy HH:mm 08/22/2006 06:30
1 MM/dd/yyyy hh:mm tt 08/22/2006 06:30 AM
2 MM/dd/yyyy H:mm 08/22/2006 6:30
3 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM

The patterns for DateTime.ToString ( 'G' ) :

0 MM/dd/yyyy HH:mm:ss 08/22/2006 06:30:07

The patterns for DateTime.ToString ( 'm' ) :

0 MMMM dd August 22

The patterns for DateTime.ToString ( 'r' ) :

0 ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Tue, 22 Aug 2006 06:30:07 GMT

The patterns for DateTime.ToString ( 's' ) :

0 yyyy'-'MM'-'dd'T'HH':'mm':'ss 2006-08-22T06:30:07

The patterns for DateTime.ToString ( 'u' ) :

0 yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2006-08-22 06:30:07Z

The patterns for DateTime.ToString ( 'U' ) :

0 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07

The patterns for DateTime.ToString ( 'y' ) :

0 yyyy MMMM 2006 August

Building a custom DateTime.ToString Patterns

The following details the meaning of each pattern character. Note the K and z character.
d Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd Represents the full name of the day of the week (Monday, Tuesday etc)
h 12-hour clock hour (e.g. 7)
hh 12-hour clock, with a leading 0 (e.g. 07)
H 24-hour clock hour (e.g. 19)
HH 24-hour clock hour, with a leading 0 (e.g. 19)
m Minutes
mm Minutes with a leading zero
M Month number
MM Month number with leading zero
MMM Abbreviated Month Name (e.g. Dec)
MMMM Full month name (e.g. December)
s Seconds
ss Seconds with leading zero
t Abbreviated AM / PM (e.g. A or P)
tt AM / PM (e.g. AM or PM
y Year, no leading zero (e.g. 2001 would be 1)
yy Year, leadin zero (e.g. 2001 would be 01)
yyy Year, (e.g. 2001 would be 2001)
yyyy Year, (e.g. 2001 would be 2001)
K Represents the time zone information of a date and time value (e.g. +05:00)
z With DateTime values, represents the signed offset of the local operating system's time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
zz As z but with leadin zero (e.g. +06)
zzz With DateTime values, represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. (e.g. +06:00)
f Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
ff Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.
fff Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
ffff Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffff Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
ffffff Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffffff Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
F Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero.
: Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds.
/ Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days.
" Represents a quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Your application should precede each quotation mark with an escape character (\).
' Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.
%c Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers.
||\c || Represents the escape character, and displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, the application should use two escape characters ("\\").
Any other character copies any other character to the result string, without affecting formatting. ||