Question: referencing control in formview gives error

C

Cirene

I cannot reference a calendar control in my formview control. (I want the
calendar's date to be set to "Today" whenever they enter insert mode.)

Here's part of the formview...
<asp:FormView ID="FormView1" runat="server" CellPadding="4"
DataKeyNames="ListingId"
DataSourceID="sdsListingDetails" ForeColor="#333333">
:
:
<InsertItemTemplate><table cellpadding="0" cellspacing="0"
width="700">
:
:
<tr>
<td style="width: 166px" valign="top">
Bid Deadline:</td>
<td>
<asp:Calendar ID="calDeadline" runat="server"
Height="165px" SelectedDate='<%# Bind("LBidDeadline") %>'
Width="259px"></asp:Calendar>
</td>
</tr>
:
:
</InsertItemTemplate>
:
:
</asp:FormView>

Here's the code:
Protected Sub FormView1_ModeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles FormView1.ModeChanged
Select Case Me.FormView1.CurrentMode
Case FormViewMode.Insert
Dim cal As Calendar =
CType(Me.FormView1.FindControl("calDeadline"), Calendar)
cal.SelectedDate = Now.Date
End Select
End Sub

The variable 'cal' is "Nothing" everytime I set it! In fact, I cannot
reference any textboxes in the formview as well.

I know it's probably something simple.

Any ideas?
 
M

Michael Nemtsev, [MVP]

Hello Cirene,

What's the calendar control name in the page source, when page is rendered?

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


C> I cannot reference a calendar control in my formview control. (I
C> want the calendar's date to be set to "Today" whenever they enter
C> insert mode.)
C>
C> Here's part of the formview...
C> <asp:FormView ID="FormView1" runat="server" CellPadding="4"
C> DataKeyNames="ListingId"
C> DataSourceID="sdsListingDetails" ForeColor="#333333">
C> :
C> :
C> <InsertItemTemplate><table cellpadding="0" cellspacing="0"
C> width="700">
C> :
C> :
C> <tr>
C> <td style="width: 166px" valign="top">
C> Bid Deadline:</td>
C> <td>
C> <asp:Calendar ID="calDeadline" runat="server"
C> Height="165px" SelectedDate='<%# Bind("LBidDeadline") %>'
C> Width="259px"></asp:Calendar>
C> </td>
C> </tr>
C> :
C> :
C> </InsertItemTemplate>
C> :
C> :
C> </asp:FormView>
C> Here's the code:
C> Protected Sub FormView1_ModeChanged(ByVal sender As Object, ByVal
C> e As
C> System.EventArgs) Handles FormView1.ModeChanged
C> Select Case Me.FormView1.CurrentMode
C> Case FormViewMode.Insert
C> Dim cal As Calendar =
C> CType(Me.FormView1.FindControl("calDeadline"), Calendar)
C> cal.SelectedDate = Now.Date
C> End Select
C> End Sub
C> The variable 'cal' is "Nothing" everytime I set it! In fact, I
C> cannot reference any textboxes in the formview as well.
C>
C> I know it's probably something simple.
C>
C> Any ideas?
C>
 
B

bruce barker

thats because they are children of the template which is a child of the
formview. so you need to do a recursive find (find children of children ...)



-- bruce (sqlwork.com)
 
C

Cirene

Here's some of it... calDeadline seems correct???

<a
href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$FormView1$calDeadline','2857')"
style="color:Black" title="October 28">28</a></td><td align="center"
style="width:14%;"><a
href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$FormView1$calDeadline','2858')"
style="color:Black" title="October 29">29</a></td><td align="center"
style="width:14%;"><a
href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$FormView1$calDeadline','2859')"
style="color:Black" title="October 30">30</a></td><td align="center"
style="width:14%;"><a
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top