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

Joel D Canfield joel at streamliine.com
Mon Oct 1 10:21:28 CDT 2007


> You shouldn't have to do a FindControl.  txtHireDate.Text = 
> ... should do it.

It doesn't; more below

> If you're using ASP 1.1 with the code-behind model

2.0

> Protected WithEvents txtHireDate As System.Web.UI.WebControls.TextBox

all there as expected, including the calendar declaration

Here's the entire contents of the vb codebehind:

	Partial Class updateemployee
		Inherits System.Web.UI.Page
		Protected DeptDDL As DropDownList
		Protected WithEvents txtHireDate As TextBox
		Protected WithEvents calHireDate As Calendar
		Sub Page_Load()
			DeptDDL.Items.Insert(0, New
ListItem("Information Technology", 9))
		End Sub
		Sub calHireDate_SelectionChanged(ByVal sender As Object,
ByVal e As EventArgs)
			txtHireDate.Text =
calHireDate.SelectedDate.ToString("d")
		End Sub
	End Class

and the entire template field:

  <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>

when I select a date in the popup calendar, I get the error "Object
reference not set to an instance of an object" referencing this line:

    Line 10:  txtHireDate.Text = calHireDate.SelectedDate.ToString("d")

I don't even know which object it's referring to, 'txtHireDate' or
'calHireDate'

the continued assistance continues to be appreciated :)

joel



More information about the thelist mailing list