FindControl problem...

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm trying to set a Calendar Value to a control that is in the
EditItem and InsertItem Templates. It's been suggested that I use the
below lines...

TextBox t =
(TextBox)fvCapture.Row.FindControl("CaptureDateTextBox");
t.Text = Calendar1.SelectedDate.ToShortDateString();

Not quite sure what event to put it under though. Everywhere I've
used I get the below error:

Object reference not set to an instance of an object.


Can anyone help me with this one?

Thanks
 
One thing I left out... The "Object reference not set to an instance
of an object" Error is on

t.Text = Calendar1.SelectedDate.ToShortDateString();


Any quick help would be greatly appreciated.
 
One thing I left out... The "Object reference not set to an instance
of an object" Error is on

t.Text = Calendar1.SelectedDate.ToShortDateString();

Well, what part of that expression is null? It's either t, Calendar1
or Calendar1.SelectedDate. So which is it?

If t, that means the previous line of code trying to find the
"CaptureDateTextBox" control failed. If Calendar1, then your calender
control apparently doesn't exist. And if Calendar1.SelectedDate, then
apparently your calendar control exists but doesn't have a currently
selected date.

Any of those _could_ be the problem. But you haven't provided enough
information for anyone to know which it is.

The debugger is your friend. Take a look at the state of your program
when you get the exception, and find out _which_ object reference is
not set to an instance of an object. Then you'll know what the problem
is.

Pete
 
Hello Dave,

it's because you control is not found.
use the "Find control recursevly" pattern for this

http://weblogs.asp.net/eporter/archive/2007/02/24/asp-net-findcontrol-recursive-with-generics.aspx

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


D> One thing I left out... The "Object reference not set to an instance
D> of an object" Error is on
D>
D> t.Text = Calendar1.SelectedDate.ToShortDateString();
D>
D> Any quick help would be greatly appreciated.
D>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top