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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with date picker

Status
Not open for further replies.

Gill1978

Programmer
Jun 12, 2001
277
GB
Hi,

I'm using the calendar control on my webpage. The pop up works fine, however when I select the a date the pop does return the value selected to the text box ... it doesn't seem to do anything.

can anyone help??

Here's the code on aspx page:

Code:
<EditItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DateReceived") %>'></asp:TextBox>
    <a href="javascript:calendar_window=window.open('Calendar.aspx?formname=
RegAC.TextBox1','calendar_window','width=164,height=188');
calendar_window.focus()">Calendar</a> 
</EditItemTemplate>

Actual Calendar aspx:

Code:
<asp:Calendar id="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" OnDayRender="Calendar1_DayRender" showtitle="true" DayNameFormat="FirstTwoLetters" SelectionMode="Day" BackColor="#ffffff" FirstDayOfWeek="Monday" BorderColor="#000000" ForeColor="#00000" Height="60" Width="120">
</asp:Calendar>
<asp:Literal id="Literal1" runat="server"></asp:Literal>
{/CODE}

Code behind the Calendar.aspx form:
[CODE]
public partial class Calendar : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        string strjscript = "<script language='javascript'>";
        strjscript += "window.opener." + HttpContext.Current.Request.QueryString["formname"];
        strjscript += ".value = '" + Calendar1.SelectedDate.ToString("d") + "';window.close();";
        strjscript += "</script" + ">"; //Don't ask, tool bug.
        Literal1.Text = strjscript;
    }
    protected void Calendar1_DayRender(Object source, DayRenderEventArgs e)
    {
        if (e.Day.Date.ToString("d") == DateTime.Now.ToString("d"))
        {
            e.Cell.BackColor = System.Drawing.Color.LightGray;
        }

    }
}

Thanks for any help

 
Thanks for that ...

I'll have a look ... though it looks pretty similar to what I already have in c#

 
If you have a problem with the javascript, I suggest you have a look at what is rendered and post the relevant code in a thread in the javascript forum.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Try remoing this..:
+ HttpContext.Current.Request.QueryString["formname"]; and add
.document.forms[0]

 
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