|
-
Dec 23rd, 2002, 09:04 AM
#1
Thread Starter
Frenzied Member
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.
-
Dec 23rd, 2002, 10:29 AM
#2
how about showing us your code?!
-
Dec 23rd, 2002, 10:58 AM
#3
Thread Starter
Frenzied Member
If the error message is correct, line 12 would be Literal1.text = strjscript
VB Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="calendar.aspx.vb" Inherits="pbss.calendar"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>PBSS - Choose Date</title>
<script runat="server">
Public Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)
Dim strjscript as string = "<script language=""javascript"">"
strjscript = strjscript & "function SendBack() {"
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>
-
Dec 23rd, 2002, 11:04 AM
#4
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.
-
Dec 23rd, 2002, 02:30 PM
#5
Thread Starter
Frenzied Member
ok, I found the line thats causing the error.
<body onload="JavaScript:SendBack()">
any suggestions?
-
Dec 24th, 2002, 03:34 PM
#6
Hyperactive Member
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.
-
Jan 6th, 2003, 02:05 PM
#7
Thread Starter
Frenzied Member
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?
-
Jan 6th, 2003, 03:25 PM
#8
Hyperactive Member
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:
<html>
<head>
<script language="javascript">
function GetDate(){
var win = window.open("calendarTest.aspx?targetControl=theDate", "","");
}
</script>
</head>
<body>
<form id="calendarTest">
<input type="text"
id="theDate"
name="theDate" />
<input type="button"
id="btnGetDate"
name="btnGetDate"
value="Get Date"
onclick="GetDate()" />
</form>
</body>
</html>
And here's the calendar page:
VB Code:
<script language="vb" runat="server">
Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim jscript As String = "<script language=""javascript"">"
jscript &= "SendBack('" & Calendar1.SelectedDate & "')"
jscript &= "</script" & ">"
Literal1.Text = jscript
End Sub
</script>
<html>
<script language="javascript">
function SendBack(selectedDate){
var parentWin = window.opener;
var targetControlName = '<%= Request("TargetControl") %>'
if (parentWin){
var targetControl = parentWin.document.getElementById(targetControlName);
if (targetControl){
targetControl.value = selectedDate;
window.close();
}
}
}
</script>
<body>
<form runat="server">
<asp:Literal
ID="Literal1"
Runat="server" />
<asp:Calendar
ID="Calendar1"
OnSelectionChanged="Calendar1_SelectionChanged"
Runat="server" />
</form>
</body>
</html>
-
Jan 7th, 2003, 09:34 AM
#9
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|