Results 1 to 9 of 9

Thread: calendar control [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    calendar control [RESOLVED]

    On my page I have a hyper-link that will open a page that has a calendar control. User selects the date and the original page textbox get populated with the date and the calendar page closes. This was working fine then sudddenly I began to get an Internet Explorer error.

    Line:12
    Char:1
    Error:"Object Expected"
    Code:0
    URL:"calendar.aspx?formname=add.txtstartdate.text"


    I debug through the app and I can't find the error. I tried looking for the location but not sure if it's the vb code or HTML side. Any suggestions? Just for the record, the code still works fine, once I close out the error message.
    Last edited by EyeTalion; Jan 7th, 2003 at 09:35 AM.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    how about showing us your code?!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    If the error message is correct, line 12 would be Literal1.text = strjscript

    VB Code:
    1. <%@ Page Language="vb" AutoEventWireup="false" Codebehind="calendar.aspx.vb" Inherits="pbss.calendar"%>
    2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    3. <HTML>
    4.     <HEAD>
    5.         <title>PBSS - Choose Date</title>
    6.         <script runat="server">
    7.     Public Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)
    8.         Dim strjscript as string = "<script language=""javascript"">"
    9.         strjscript = strjscript & "function SendBack() {"
    10.         strjscript = strjscript & "window.opener." & Httpcontext.Current.Request.Querystring("formname") & ".value = '" & Calendar1.SelectedDate & "';window.close();"
    11.         strjscript = strjscript & "}</script" & ">" 'Don't Ask, Tool Bug
    12.         Literal1.text = strjscript
    13.     End Sub
    14.    
    15.     Private Sub Calendar1_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs)
    16.        If e.Day.Date = datetime.now().tostring("d") Then
    17.        e.Cell.BackColor = System.Drawing.Color.LightGray
    18.        End If
    19.     End Sub
    20.  
    21.         </script>

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    do a view source in the browser because the error is being caused on the client and has nothing to do with your asp .net code. The problem is more than likely the javascript your are outputting is not correct.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    ok, I found the line thats causing the error.

    <body onload="JavaScript:SendBack()">


    any suggestions?

  6. #6
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Why do you have that body onload call? that doesn't make any sense, anyway, that function won't exist until the user causes the Calendar1_SelectionChanged to fire. So calling it on the body onload will generate the error(and i'm assuming that body onload code is in your calendar page). I remember this code from a while back, pretty sure you shouldn't need that body onload eventhandler or perhaps you maybe wanted a different eventhandler.

  7. #7

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    the problem is when I take out: onload="JavaScript:SendBack()" from the body tag, my textbox doesn't get populated with the date...does it belong in another tag?

  8. #8
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    hmmm...i'm thinkin that you want to dynamically build the code that actually executes the javascript function SendBack() not the source of the function itself. You can build that function when the page loads, then when the SelectionChanged event is raised you'll just build the javascript code that executes your already built function. So, i'm pretty sure the following is a little different from the way you did but maybe it'll help:
    Here's the parent page:
    VB Code:
    1. <html>
    2.     <head>
    3.     <script language="javascript">
    4.     function GetDate(){
    5.         var win = window.open("calendarTest.aspx?targetControl=theDate", "","");
    6.     }
    7.     </script>
    8.     </head>
    9.     <body>
    10.         <form id="calendarTest">
    11.             <input type="text"
    12.                 id="theDate"
    13.                 name="theDate" />
    14.             <input type="button"
    15.                 id="btnGetDate"
    16.                 name="btnGetDate"
    17.                 value="Get Date"
    18.                 onclick="GetDate()" />
    19.         </form>
    20.     </body>
    21. </html>

    And here's the calendar page:
    VB Code:
    1. <script language="vb" runat="server">
    2. Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    3.     Dim jscript As String = "<script language=""javascript"">"
    4.     jscript &= "SendBack('" & Calendar1.SelectedDate & "')"
    5.     jscript &= "</script" & ">"
    6.     Literal1.Text = jscript
    7. End Sub
    8. </script>
    9. <html>
    10.     <script language="javascript">
    11.     function SendBack(selectedDate){
    12.         var parentWin = window.opener;
    13.         var targetControlName = '<%= Request("TargetControl") %>'
    14.         if (parentWin){
    15.             var targetControl = parentWin.document.getElementById(targetControlName);
    16.             if (targetControl){
    17.                 targetControl.value = selectedDate;
    18.                 window.close();
    19.             }
    20.         }
    21.     }
    22.     </script>
    23.     <body>
    24.         <form runat="server">
    25.             <asp:Literal
    26.                 ID="Literal1"
    27.                 Runat="server" />
    28.             <asp:Calendar
    29.                 ID="Calendar1"
    30.                 OnSelectionChanged="Calendar1_SelectionChanged"
    31.                 Runat="server" />
    32.         </form>
    33.     </body>
    34. </html>

  9. #9

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks pvb...that did it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width