Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET Date Picker Code question

Status
Not open for further replies.

ddrake

Technical User
Mar 19, 2003
92
Can anyone help me figure this out. I have date picker code that works famously inside a regular Web Form, but when I place it inside the FormView Tags inside the EditItemTemplate, when clicking the calendar by the textbox it will not pop up.

Any Idea why the code below works great in a regular form but when placing in inside the FormView EditItemTemplate, it will not work the same. Should I add something to the Sub....My Good Code is below.
'==========================================================================
GOOD CODE WHEN NOT IN A FORMVIEW - BUT WHEN ADDING IT TO A FORMVIEW EDITITEMTEMPLATE - The Calendar Wont' Pop --- Why? Please.....
'==========================================================================

<%@ Page Language="VB" Trace="false" aspCompat="True" SmartNavigation="True" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace ="System.Drawing"%>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls"%>
<html xmlns=" >
<head id="Head1" runat="server">

<script language="VB" runat="server">

Sub ibtnCal1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnCal1.Click
cldpickdate1.Visible = True
End Sub
Sub cldpickdate1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cldpickdate1.SelectionChanged
cldpickdate1.Visible = False
Date1Textbox.Text = cldpickdate1.SelectedDate
End Sub


Sub ibtnCal1End_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnCal1End.Click
cldpickdate1End.Visible = True
End Sub
Sub cldpickdate1End_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cldpickdate1End.SelectionChanged
cldpickdate1End.Visible = False
Date1EndTextbox.Text = cldpickdate1End.SelectedDate
End Sub
</script>

<title>Date Picker</title>
</head>
<body><center>
<form id="form1" runat="server">

<asp:TextBox ID="Date1Textbox" runat="server"
Width="75px" ReadOnly="true" BackColor="LemonChiffon" Font-Names="Verdana" Font-Size="8pt" ForeColor="Firebrick"></asp:TextBox>
<asp:ImageButton ID="ibtnCal1" runat="server" CausesValidation="False"
ImageUrl="Images/calendar.gif" /><br />
<asp:Calendar ID="cldpickdate1" runat="server" BackColor="White" BorderColor="#0066ff"
BorderStyle="Groove" CellPadding="4" DayNameFormat="FirstLetter" Font-Names="Verdana"
Font-Size="8pt" ForeColor="Black" Height="163px" TitleFormat="Month"
Width="111px" Visible="False">
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#660000" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TitleStyle BackColor="LightSteelBlue" BorderColor="Black" Font-Bold="True" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CCCCCC" />
</asp:Calendar>
<br />
<br />

<asp:TextBox ID="Date1EndTextbox" runat="server"
Width="75px" ReadOnly="true" BackColor="LemonChiffon" Font-Names="Verdana" Font-Size="8pt" ForeColor="Firebrick"></asp:TextBox>
<asp:ImageButton ID="ibtnCal1End" runat="server" CausesValidation="False"
ImageUrl="Images/calendar.gif" /><br />
<asp:Calendar ID="cldpickdate1End" runat="server" BackColor="White" BorderColor="#0066ff"
BorderStyle="Groove" CellPadding="4" DayNameFormat="FirstLetter" Font-Names="Verdana"
Font-Size="8pt" ForeColor="Black" Height="163px" TitleFormat="Month"
Width="111px" Visible="False">
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#660000" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TitleStyle BackColor="LightSteelBlue" BorderColor="Black" Font-Bold="True" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CCCCCC" />
</asp:Calendar>

</form>
</center>
</body>
</html>
 
Thanks .... Figured it out for VB.Net in a FormView code is below:
The Answer was Dimming & Adding FindControl
===========================================================
<html xmlns=" >
<head id="Head1" runat="server">
<title>Date Picker</title>
<script language="VB" runat="server">
Sub showDate1cal(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)
FormView1.FindControl("Date1Calendar").Visible = True
End Sub
Sub Date1Textbox_Selected(ByVal sender As Object, ByVal e As EventArgs)
Dim Date1Textbox
Date1Textbox = FormView1.FindControl("Date1Textbox")
Dim Date1Cal
Date1Cal = FormView1.FindControl("Date1Calendar")
Date1Textbox.text = Format(Date1Cal.SelectedDate, "MM/dd/yy")
FormView1.FindControl("Date1Calendar").Visible = False
End Sub

Sub showDate1Endcal(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)
FormView1.FindControl("Date1EndCalendar").Visible = True
End Sub

Sub Date1EndTextbox_Selected(ByVal sender As Object, ByVal e As EventArgs)
Dim Date1EndTextbox
Date1EndTextbox = FormView1.FindControl("Date1EndTextbox")
Dim Date1EndCal
Date1EndCal = FormView1.FindControl("Date1EndCalendar")
Date1EndTextbox.text = Format(Date1EndCal.SelectedDate, "MM/dd/yy")
FormView1.FindControl("Date1EndCalendar").Visible = False
End Sub
</script>
</head>
<body><span style="font-size: 8pt; font-family: Verdana">

<form id="form1" runat="server">

<asp:FormView ID="FormView1" runat="server" DefaultMode="Edit" >
<EditItemTemplate>
<table>
<tr>
<td style="width: 124px" >
<span style="font-size: 8pt">
Date 1:</span></td>
<td style="width: 233px" >
<asp:TextBox ID="Date1TextBox" runat="server"
Width="75px" ReadOnly="True" BackColor="LemonChiffon" Font-Names="Verdana" Font-Size="8pt" ForeColor="Firebrick"></asp:TextBox>
<asp:ImageButton ID="ibtncal1" runat="server" onClick="showDate1cal" ImageUrl="images/calendar.gif" />
</td>
</tr>

<asp:Calendar ID="Date1Calendar" runat="server" BackColor="White" BorderColor="#0066ff"
BorderStyle="Groove" CellPadding="4" DayNameFormat="FirstLetter" Font-Names="Verdana"
Font-Size="8pt" ForeColor="Black" Height="163px" TitleFormat="Month"
Width="111px" Visible="False" OnSelectionChanged="Date1Textbox_Selected" >
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#660000" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TitleStyle BackColor="LightSteelBlue" BorderColor="Black" Font-Bold="True" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CCCCCC" />
</asp:Calendar>
<tr>
<td style="width: 124px" >
<span style="font-size: 8pt">
Date 1 End:</span></td>
<td style="width: 233px" >
<asp:TextBox ID="Date1EndTextbox" runat="server" BackColor="LemonChiffon" Font-Names="Verdana"
Font-Size="8pt" ForeColor="Firebrick" ReadOnly="True" Width="75px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" onClick="showDate1Endcal" ImageUrl="images/calendar.gif" />
</td>
</tr>

<asp:Calendar ID="Date1EndCalendar" runat="server" BackColor="White" BorderColor="#0066ff"
BorderStyle="Groove" CellPadding="4" DayNameFormat="FirstLetter" Font-Names="Verdana"
Font-Size="8pt" ForeColor="Black" Height="163px" TitleFormat="Month"
Width="111px" Visible="False" OnSelectionChanged="Date1EndTextbox_Selected" >
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#660000" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TitleStyle BackColor="LightSteelBlue" BorderColor="Black" Font-Bold="True" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CCCCCC" />
</asp:Calendar>

</table>

</EditItemTemplate>
<InsertItemTemplate>
[Insert Items Here ]
</InsertItemTemplate>

<ItemTemplate>
[Read Only Items Here]
</ItemTemplate>
</asp:FormView>

</form></span>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top