Tuesday, February 14, 2012

Working with Date using AJAX




Show Date using AJAX in ASP.Net




Step 1)Open a ASP.Net AJAX enable website in your visual Studio .

Step 2)Add below code in your ASP.net page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="aaa.aspx.cs" Inherits="aaa" %>

<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls"
    TagPrefix="BDP" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Select date:-<bdp:basicdatepicker
                    id="BasicDatePicker1" runat="server" displaytype="TextBoxAndButton" onselectionchanged="BasicDatePicker1_SelectionChanged"></bdp:basicdatepicker>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Show date" />
                <asp:Label ID="Label1" runat="server" Width="225px"></asp:Label>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
            </ContentTemplate>
        </asp:UpdatePanel>
       
   
    </div>
    </form>
</body>
</html>
Step 3) Put below code in your code behind of ASP.Net page
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class aaa : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void BasicDatePicker1_SelectionChanged(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Label1.Text = Convert.ToString(this.BasicDatePicker1.SelectedDate);
    }
}

1 comment: