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

Tab Alleman talleman at Lumpsum.com
Mon Oct 1 09:20:01 CDT 2007


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

If you're using ASP 1.1 with the code-behind model, it sounds like it didn't automatically create your object reference for you.  You can usually fix this by switching to design view and then back to code view on your .aspx page.  If that doesn't fix it, look for a line near the top of your code-behind (you may have to open the automatically generated code blocks to see it) that looks like this:

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

if you don't find it anywhere, add it.   There should also be a similar line for your Calendar object.

Hope this helps,
T



> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of Joel D Canfield
> Sent: Friday, September 28, 2007 7:21 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] error using .NET calendar to set value of textbox
> 
> 
> 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
> -- 
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester 
> and archives of thelist go to: http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 



More information about the thelist mailing list