srobia
asked on
ASP.NET Calendar Control Weird
OK I'm using .NET 1.1 with a calendar control. When I put the calendar control on an .aspx it works just fine. When I bring the calendar (exact same function in the code behind) to a user control it no longer works. It gives me a javascript error: "Object expected". Any idea what is going on? Is my user control not passing the event up to the page level?
ASKER
here is the control code (I am using a basepage):
<form runat="server" ID="Form1" method="post">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" style="HEIGHT: 16px">
<asp:TextBox id="txtDate" runat="server" Width="100px"></asp:TextBo x>
</td>
<td valign="top" style="HEIGHT: 16px">
<asp:Button id="btnSelect" runat="server" Text="Select"></asp:Button >
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<asp:Calendar id="calDate" runat="server" Width="160px" BackColor="White"
DayNameFormat="FirstLetter " ForeColor="Black" Height="180px" Font-Size="8pt" Font-Names="Verdana" BorderColor="#999999"CellP adding="4" Visible="True" onselectionchanged="calDat e_Selectio nChanged"> </asp:Cale ndar>
</td>
</tr>
</table>
</form>
<P></P>
And here is the code behind for the control:
Protected Sub calDate_SelectionChanged(B yVal sender As Object, ByVal e As EventArgs)
Dim dtDate As System.DateTime = calDate.SelectedDate
txtDate.Text = dtDate.ToShortDateString()
End Sub
And here is the page (again I am using a basepage):
<%@ Register tagprefix="body" tagname="body" src="calControl.ascx" %>
<body:body runat="Server" ID="body" NAME="body" />
Thanks!!
<form runat="server" ID="Form1" method="post">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" style="HEIGHT: 16px">
<asp:TextBox id="txtDate" runat="server" Width="100px"></asp:TextBo
</td>
<td valign="top" style="HEIGHT: 16px">
<asp:Button id="btnSelect" runat="server" Text="Select"></asp:Button
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<asp:Calendar id="calDate" runat="server" Width="160px" BackColor="White"
DayNameFormat="FirstLetter
</td>
</tr>
</table>
</form>
<P></P>
And here is the code behind for the control:
Protected Sub calDate_SelectionChanged(B
Dim dtDate As System.DateTime = calDate.SelectedDate
txtDate.Text = dtDate.ToShortDateString()
End Sub
And here is the page (again I am using a basepage):
<%@ Register tagprefix="body" tagname="body" src="calControl.ascx" %>
<body:body runat="Server" ID="body" NAME="body" />
Thanks!!
and when do u get the error? did u click sth when the page is loaded and get error?
locitt.
locitt.
ASKER
I get the error when I click on a date. The page loads fine and displays the calendar. It just doesn't work when I click on a date on the calendar.
Thanks!!
Thanks!!
add a try / catch block around that method... what's the runtime error?
i just recreated your control, put it in a web page, and it works fine.
Protected Sub calDate_SelectionChanged(B yVal sender As Object, ByVal e As EventArgs)
Try
Dim dtDate As System.DateTime = calDate.SelectedDate
txtDate.Text = dtDate.ToShortDateString()
Catch ex as Exception
Response.Write(ex.ToString ());
End Try
End Sub
i just recreated your control, put it in a web page, and it works fine.
Protected Sub calDate_SelectionChanged(B
Try
Dim dtDate As System.DateTime = calDate.SelectedDate
txtDate.Text = dtDate.ToShortDateString()
Catch ex as Exception
Response.Write(ex.ToString
End Try
End Sub
ASKER
I've tried putting a breakpoint on the code, but the client side never gets to call it because it screams about the javascript error: "Object Unidentified"
sounds like you don't have the javascript files there.
for the default installation of iis you should see the following (assuming .net 1.1):
C:\Inetpub\wwwroot\aspnet_ client\sys tem_web\1_ 1_4322
this should have three files in it:
SmartNav.htm
SmartNav.js
WebUIValidation.js
in this instance, the SmartNav.js is the file it's looking for.
for the default installation of iis you should see the following (assuming .net 1.1):
C:\Inetpub\wwwroot\aspnet_
this should have three files in it:
SmartNav.htm
SmartNav.js
WebUIValidation.js
in this instance, the SmartNav.js is the file it's looking for.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It was the base page issue -- I just moved the code up to the page level and everything was fixed. Thanks for the help!!
that's 1 possibilitym, send your code.
locitt.