Forum Moderators: open

Message Too Old, No Replies

Calendar control

         

Blelisa

3:41 pm on May 16, 2005 (gmt 0)

10+ Year Member



am very new to asp.net. In fact this is my very first experience with it. I have some knowledge of classic asp. I am trying to make a form that where the date entry is I can have a pop-up calendar for the user to pick a date from. I am using the article from this site: Populating Form Inputs Using the Calendar Control. However I can not get this to work. I keep getting an error when I click on the text Calendar to get the control to pop up. The error I get is:
Line 1
Char 142
unterminate string constant
Can anyone help?
Below I have listed my code:
Code from page with form on it for user input. It is a classic asp page:
<form name="frmCalendar">
<input name="txtDate" type="text" />
<a href="javascript:calendar_window=window.open('/calendar.aspx?
formname=frmCalendar.txtDate','calendar_window', width=154,height=188');calendar_window.focus()">
Calendar
</a>
</form>

CODE FROM Calendar.aspx
<%@ Page Language="vb" %>

<script runat="server">
Private Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)
Dim strjscript as string = "<script language=""javascript"">"
strjscript = strjscript & "window.opener." & Httpcontext.Current.Request.Querystring("formname") & ".value = '" & Calendar1.SelectedDate & "';window.close();"
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
Literal1.text = strjscript
End Sub

Private Sub Calendar1_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs)
If e.Day.Date = datetime.now().tostring("d") Then
e.Cell.BackColor = System.Drawing.Color.LightGray
End If
End Sub
</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>Choose a Date</title>
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
<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">
<TitleStyle backcolor="#000080" forecolor="#ffffff" />
<NextPrevStyle backcolor="#000080" forecolor="#ffffff" />
<OtherMonthDayStyle forecolor="#c0c0c0" />
</asp:Calendar>
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</form>
</body>
</html>

txbakers

4:52 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi - it sounds like you and I are both learning as we go!

From the look of your code, the problem should be here (I added the single quote in red):

window.open('/calendar.aspx?
formname=frmCalendar.txtDate','calendar_window',' width=154,height=188');

That would cause the unterminated string constant.

Blelisa

5:04 pm on May 16, 2005 (gmt 0)

10+ Year Member



That did it! Thanks Txbakers! It always seems to be the smallest, stupidest thing that hangs me up!

Blelisa

6:17 pm on May 16, 2005 (gmt 0)

10+ Year Member



One More Thing,

Okay, got the Calendar Control to work wonderfully, thanks to the help, however now I cannot get the date that the user selects to appear in the form textbox so that when the user presses submit the information gets emailed along with the rest of the data. Here is my code:
<%@ Page Language="vb" %>
<script runat="server">
Private Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)
Dim strjscript as string = "<script language=""javascript"">"
strjscript &= "window.opener." & _
Httpcontext.Current.Request.Querystring("frmCalendar") & ".value = '" &_
Calendar1.SelectedDate & "';window.close();"
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
Literal1.text = strjscript
End Sub

Private Sub Calendar1_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs)
If e.Day.Date = datetime.now().tostring("d") Then
e.Cell.BackColor = System.Drawing.Color.LightGray
End If
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>Choose a Date</title>
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">

<asp:Calendar BackColor="#ffffff" BorderColor="#000000" DayNameFormat="FirstTwoLetters" FirstDayOfWeek="Monday" ForeColor="#00000" Height="100" id="Calendar1" runat="server" SelectedDayStyle-BackColor="#000000" SelectionMode="Day" showtitle="true" Width="120" OnDayRender="Calendar1_dayrender" OnSelectionChanged="Calendar1_SelectionChanged">
<TitleStyle backcolor="#000080" forecolor="#ffffff" /> <TodayDayStyle backcolor="CornSilk" forecolor="Blue" font-bold="true" />
<NextPrevStyle backcolor="#000080" forecolor="#ffffff" /> <OtherMonthDayStyle forecolor="#c0c0c0" />
</asp:Calendar>
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</form>
</body>
</html>