Calendar without Autopostback

G

Guest

Hi
I need a calendar user control with out refresh.this code is refreshing
the page for every action like change to next month or next year.
Thanx
Ramakrishna
--popupcalendar.ascx---
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="popUpCalendar.ascx.vb" Inherits="pmap110.popUpCalendar"
enableViewState="True"%>
<asp:panel id="pnlCalendar" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" Width="145px"
Height="176px" runat="server" BackColor="#000071">
<asp:Calendar id="Calendar1" Width="145" Height="160px" runat="server"
BackColor="White" BorderColor="Black"
BorderStyle="Solid" NextMonthText="<IMG src='/images/arrowleft.gif'
border='0'>" PrevMonthText="<IMG src='/images/arrowright.gif' border='0'>">
<TodayDayStyle BackColor="AliceBlue"></TodayDayStyle>
<DayStyle Font-Size="8pt" Font-Names="Arial"></DayStyle>
<DayHeaderStyle Font-Size="10pt" Font-Underline="True" Font-Names="Arial"
BorderStyle="None" BackColor="#E0E0E0"></DayHeaderStyle>
<SelectedDayStyle Font-Size="8pt" Font-Names="Arial" Font-Bold="True"
ForeColor="White" BackColor="Navy"></SelectedDayStyle>
<TitleStyle Font-Size="10pt" Font-Names="Arial" Font-Bold="True"
ForeColor="White" BackColor="Navy"></TitleStyle>
<OtherMonthDayStyle ForeColor="Gray"></OtherMonthDayStyle>
</asp:Calendar>
<TABLE WIDTH="182px" BORDER="0" CELLSPACING="1" CELLPADDING="1">
<TR>
<TD align=left ><asp:imagebutton id="ImageButton2" AlternateText="Previous
Year" runat="server" ImageUrl="Images\arrowright.gif"
CausesValidation="False"></asp:imagebutton></TD>
<TD align=center ><asp:button id="btnClose" Width="58px" runat="server"
Text="Close" Font-Size="XX-Small"></asp:button></TD>
<TD align=right ><asp:imagebutton id="Imagebutton1" AlternateText="Next
Year" BorderColor=#ff3300 runat="server" ImageUrl="Images\arrowleft.gif"
CausesValidation="False"></asp:imagebutton></TD>
</TR>
</TABLE>
</asp:panel>
---popupcalendar.ascx.vb---
Public Class popUpCalendar : Inherits System.Web.UI.UserControl
Implements IPostBackEventHandler
' Defines the Click event.
Public Event Click As EventHandler
Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
Protected WithEvents btnClose As System.Web.UI.WebControls.Button
Protected WithEvents ImageButton2 As System.Web.UI.WebControls.ImageButton
Protected WithEvents Imagebutton1 As System.Web.UI.WebControls.ImageButton
Protected WithEvents pnlCalendar As System.Web.UI.WebControls.Panel

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
' Method of IPostBackEventHandler that raises change events.
Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements
IPostBackEventHandler.RaisePostBackEvent
OnClick(EventArgs.Empty)
End Sub
'' Invokes delegates registered with the Click event.
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
output.Write("<INPUT TYPE=submit name=" & Me.UniqueID & _
" Value='Click Me' />")
End Sub

Public Sub displayCalendar(ByVal sCalToolText As String, _
ByVal dSelectedDate As Date, _
ByVal sDateFieldName As String, _
ByVal iTop As Integer, _
ByVal iLeft As Integer)

'************************************************************************
'Purpose: Displays & hides the calendar.
'Input: sCalToolText - Text to use as the tooltip text for the
calendar
' dSelectedDate - Date to set as the selected date for the calendar
' txtDate - string containing name of applicable textbox
' iTop - top position of calendar
' iLeft - left position of calendar

'************************************************************************

'If the calendar is visible, but it is displayed for a different field
'than the one selected, then hide it
If pnlCalendar.Visible = True And
Calendar1.Attributes.Item("selectedfield") <> sDateFieldName Then
hideCalendar()
End If

'If the calendar is hidden, then position it and show it, otherwise
hide it
If pnlCalendar.Visible = False Then

'Set the location of the calendar
pnlCalendar.Style.Item("top") = iTop
pnlCalendar.Style.Item("left") = iLeft

'If a valid date is passed in, then set this date as the
selected date
'on the calendar. Otherwise display the current month and year
If IsDate(dSelectedDate) Then
'Setting the selected date property will tell the calendar to
'highlight the date assigned to this property.
Calendar1.SelectedDate = dSelectedDate

'Setting the visible date property will tell the calendar to
'initially display the month and year of the date assigned to
'this property.
Calendar1.VisibleDate = dSelectedDate
Else
Calendar1.SelectedDate = #12:00:00 AM#
Calendar1.VisibleDate = Now
End If

'Set the tooltip text and id of the selected field
Calendar1.ToolTip = sCalToolText
Calendar1.Attributes.Item("SelectedField") = sDateFieldName

'Show the calendar
pnlCalendar.Visible = True
Else
'Hide the calendar
hideCalendar()
End If

End Sub

Public Sub Calendar1_SelectionChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged

'************************************************************************
'Purpose: Write the selected date to the appropriate text field.

'************************************************************************
Dim txtDate As TextBox

'get the textbox that the date should be written to
txtDate = Page.FindControl(Calendar1.Attributes.Item("SelectedField"))

'Write value to appropriate textbox
txtDate.Text = Format(Calendar1.SelectedDate, "MMM dd, yyyy")

'Hide the calendar
hideCalendar()

End Sub
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
'make the other months dates invisible.
If e.Day.IsOtherMonth Then
e.Cell.Text = ""
e.Cell.BorderStyle = BorderStyle.None
e.Cell.Height = New Unit("0px")
End If
If (e.Day.IsToday) Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End Sub

Public Sub hideCalendar()
'Hide the calendar
pnlCalendar.Visible = False
End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClose.Click
hideCalendar()
End Sub

Private Sub ImageButton2_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
If Year(Calendar1.VisibleDate) = 1 Then
Calendar1.VisibleDate = Now
End If
Calendar1.VisibleDate = Calendar1.VisibleDate.AddYears(-1)
End Sub

Private Sub Imagebutton1_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles Imagebutton1.Click
If Year(Calendar1.VisibleDate) = 1 Then
Calendar1.VisibleDate = Now
End If
Calendar1.VisibleDate = Calendar1.VisibleDate.AddYears(1)
End Sub
End Class
----------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top