[thelist] error using .NET calendar to set value of textbox

Joel D Canfield joel at streamliine.com
Fri Sep 28 18:21:15 CDT 2007


Two text input fields, HireDate and TermDate; I want to use the .NET
Calendar to update them.

Here's the back end:

    Sub calHireDate_SelectionChanged(ByVal sender As Object, ByVal e As
EventArgs)
        CType(FindControl("txtHireDate"), TextBox).Text =
calHireDate.SelectedDate.ToString()
    End Sub

I suspect that since I have no clue how FindControl works and can't seem
to find a good description, that's where my error is.

Front end code:

    <asp:TemplateField HeaderText="HireDate" SortExpression="HireDate">
        <ItemTemplate>
            <asp:Label ID="HireDateLabel" Runat="Server" 
                 Text='<%# Eval("HireDate", "{0:d}") %>' />
        </ItemTemplate>
        <EditItemTemplate>
            <asp:Label
                 id="lblHireDate"
                 Text="Hire Date:"
                 AssociatedControlID="txtHireDate"
                 Runat="server" />
            <asp:TextBox
                 id="txtHireDate"
                 Text='<%# Eval("HireDate", "{0:d}") %>'
                Runat="server" />
            <img src="images/calendar.gif" onclick="displayCalendar()"
width="16" height="17" />
            <div id="datePicker">
                <asp:Calendar
                     id="calHireDate"
                     OnSelectionChanged="calHireDate_SelectionChanged" 
                     Runat="server">
                 </asp:Calendar>
            </div>
        </EditItemTemplate>
        <ItemStyle CssClass="datacell" />
    </asp:TemplateField>

I get the error "Object reference not set to an instance of an object."

Thanks to one and all, once again.

joel



More information about the thelist mailing list