S
Scott McNair
Hi,
I've created a simple calendar control for use in my company's site.
The control works fine in the test page I wrote it against, but when I
drop it into the page I want it on, it won't fire any events inside the
control. It will post back to the server, but when it returns nothing
has happened.
I'm using the ComfortASP AJAX control within my custom control. Due to
the sheer length of my target form I can't include the code for that
(but if anybody wants to see it I can email it to them), but the code
for the ascx follows:
HTML
----
<%@ Control Language="vb" AutoEventWireup="false"
CodeBehind="DatePicker.ascx.vb" Inherits="Application.DatePicker" %>
<%@ Register Assembly="ComfortASP" Namespace="ComfortASP"
TagPrefix="cc1" %>
<cc1:ComfortASP_Manager ID="ComfortASP_Manager1" runat="server">
</cc1:ComfortASP_Manager>
<input type="text" id="DateText" runat="server"
onfocus="document.getElementById(this.id.split('_')[0]
+'_HiddenButton').click();" />
<input type="button" runat="server" id="HiddenButton"
style="display:none" />
<span id="Calendar" runat="server" visible="false"
style="position:absolute;text-align:center;background-color:#ffffff">
<div style="text-align:right;font-size:12px;color:White;background-
color:Navy">
<asp
ropDownList ID=Month runat=server
onchange="document.getElementById(this.id.split('_')[0]
+'_HiddenMonth').click();" Font-Size="12px"></asp
ropDownList>
<asp
ropDownList ID=Year runat=server
onchange="document.getElementById(this.id.split('_')[0]
+'_HiddenYear').click();" Font-Size="12px"></asp
ropDownList>
<input type="button" runat="server" id="HiddenMonth"
style="display:none" />
<input type="button" runat="server" id="HiddenYear"
style="display:none" />
</div>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#C0FFFF"
BorderColor="Navy" Font-Names="Arial,Helvetica,sans-serif" Font-
Size="12px" ShowTitle="False"></asp:Calendar>
</span>
CODEBEHIND
----------
Partial Public Class DatePicker
Inherits System.Web.UI.UserControl
ReadOnly Property Text()
Get
Return DateText.Value
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
For I As Integer = Date.Today.Year - 100 To Date.Today.Year
Year.Items.Add(LI(I.ToString, I.ToString))
Year.SelectedValue = Date.Today.Year
Next
Month.Items.Add(LI("1", "January"))
Month.Items.Add(LI("2", "February"))
Month.Items.Add(LI("3", "March"))
Month.Items.Add(LI("4", "April"))
Month.Items.Add(LI("5", "May"))
Month.Items.Add(LI("6", "June"))
Month.Items.Add(LI("7", "July"))
Month.Items.Add(LI("8", "August"))
Month.Items.Add(LI("9", "September"))
Month.Items.Add(LI("10", "October"))
Month.Items.Add(LI("11", "November"))
Month.Items.Add(LI("12", "December"))
If Date.Today.Month = 1 Then
Month.SelectedIndex = 11
Else
Month.SelectedIndex = Date.Today.Month - 1
End If
End If
End Sub
Protected Sub HiddenButton_ServerClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
HiddenButton.ServerClick
DateText.Visible = False
Calendar.Visible = True
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Calendar1.SelectionChanged
DateText.Value = Calendar1.SelectedDate
DateText.Visible = True
Calendar.Visible = False
End Sub
Public Function LI(ByVal Value As String, ByVal Text As String) As
ListItem
Dim X As New ListItem
X.Value = Value
X.Text = Text
Return X
End Function
Private Sub HiddenMonth_ServerClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles HiddenMonth.ServerClick
Dim iDiff As Integer = Date.Today.Month - CInt
(Month.SelectedItem.Value)
'Calendar1.TodaysDate = Date.Today.AddMonths(-iDiff)
Calendar1.VisibleDate = New Date(Year.SelectedItem.Text,
Month.SelectedItem.Value, 1)
End Sub
Private Sub HiddenYear_ServerClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles HiddenYear.ServerClick
Dim iDiff As Integer = Date.Today.Year - CInt
(Year.SelectedItem.Text)
'Calendar1.TodaysDate = Date.Today.AddYears(-iDiff)
Calendar1.VisibleDate = New Date(Year.SelectedItem.Text,
Month.SelectedItem.Value, 1)
End Sub
End Class
I've created a simple calendar control for use in my company's site.
The control works fine in the test page I wrote it against, but when I
drop it into the page I want it on, it won't fire any events inside the
control. It will post back to the server, but when it returns nothing
has happened.
I'm using the ComfortASP AJAX control within my custom control. Due to
the sheer length of my target form I can't include the code for that
(but if anybody wants to see it I can email it to them), but the code
for the ascx follows:
HTML
----
<%@ Control Language="vb" AutoEventWireup="false"
CodeBehind="DatePicker.ascx.vb" Inherits="Application.DatePicker" %>
<%@ Register Assembly="ComfortASP" Namespace="ComfortASP"
TagPrefix="cc1" %>
<cc1:ComfortASP_Manager ID="ComfortASP_Manager1" runat="server">
</cc1:ComfortASP_Manager>
<input type="text" id="DateText" runat="server"
onfocus="document.getElementById(this.id.split('_')[0]
+'_HiddenButton').click();" />
<input type="button" runat="server" id="HiddenButton"
style="display:none" />
<span id="Calendar" runat="server" visible="false"
style="position:absolute;text-align:center;background-color:#ffffff">
<div style="text-align:right;font-size:12px;color:White;background-
color:Navy">
<asp
onchange="document.getElementById(this.id.split('_')[0]
+'_HiddenMonth').click();" Font-Size="12px"></asp
<asp
onchange="document.getElementById(this.id.split('_')[0]
+'_HiddenYear').click();" Font-Size="12px"></asp
<input type="button" runat="server" id="HiddenMonth"
style="display:none" />
<input type="button" runat="server" id="HiddenYear"
style="display:none" />
</div>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#C0FFFF"
BorderColor="Navy" Font-Names="Arial,Helvetica,sans-serif" Font-
Size="12px" ShowTitle="False"></asp:Calendar>
</span>
CODEBEHIND
----------
Partial Public Class DatePicker
Inherits System.Web.UI.UserControl
ReadOnly Property Text()
Get
Return DateText.Value
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
For I As Integer = Date.Today.Year - 100 To Date.Today.Year
Year.Items.Add(LI(I.ToString, I.ToString))
Year.SelectedValue = Date.Today.Year
Next
Month.Items.Add(LI("1", "January"))
Month.Items.Add(LI("2", "February"))
Month.Items.Add(LI("3", "March"))
Month.Items.Add(LI("4", "April"))
Month.Items.Add(LI("5", "May"))
Month.Items.Add(LI("6", "June"))
Month.Items.Add(LI("7", "July"))
Month.Items.Add(LI("8", "August"))
Month.Items.Add(LI("9", "September"))
Month.Items.Add(LI("10", "October"))
Month.Items.Add(LI("11", "November"))
Month.Items.Add(LI("12", "December"))
If Date.Today.Month = 1 Then
Month.SelectedIndex = 11
Else
Month.SelectedIndex = Date.Today.Month - 1
End If
End If
End Sub
Protected Sub HiddenButton_ServerClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
HiddenButton.ServerClick
DateText.Visible = False
Calendar.Visible = True
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Calendar1.SelectionChanged
DateText.Value = Calendar1.SelectedDate
DateText.Visible = True
Calendar.Visible = False
End Sub
Public Function LI(ByVal Value As String, ByVal Text As String) As
ListItem
Dim X As New ListItem
X.Value = Value
X.Text = Text
Return X
End Function
Private Sub HiddenMonth_ServerClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles HiddenMonth.ServerClick
Dim iDiff As Integer = Date.Today.Month - CInt
(Month.SelectedItem.Value)
'Calendar1.TodaysDate = Date.Today.AddMonths(-iDiff)
Calendar1.VisibleDate = New Date(Year.SelectedItem.Text,
Month.SelectedItem.Value, 1)
End Sub
Private Sub HiddenYear_ServerClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles HiddenYear.ServerClick
Dim iDiff As Integer = Date.Today.Year - CInt
(Year.SelectedItem.Text)
'Calendar1.TodaysDate = Date.Today.AddYears(-iDiff)
Calendar1.VisibleDate = New Date(Year.SelectedItem.Text,
Month.SelectedItem.Value, 1)
End Sub
End Class