FormView problems

J

justin

Hello, I am having problems modifying controls that are in a FormView.
What I am trying to do with the code below is show a TextBox and a
Calendar in a FormView. When the user changes the selected date in the
calendar the new date should show in the TextBox (this is a slimmed
down version of my end product to help simplify what I am showing).

<asp:FormView ID="FormView1" DefaultMode="Edit" runat="server"
Height="249px" DataSourceID="someDataSource"
OnPageIndexChanging="FormView1_PageIndexChanging" Width="290px">
<EditItemTemplate>
<asp:Calendar ID="Calendar2" runat="server"
OnSelectionChanged="Calendar2_SelectionChanged">
</asp:Calendar>
<asp:TextBox ID="textbox1" runat="server" Text ="asdfasdf"></
asp:TextBox>
</EditItemTemplate>
</asp:FormView>

protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
Calendar toAccess = (Calendar)FormView1.FindControl("Calendar2");
TextBox toShow = (TextBox)FormView1.FindControl("textbox1");

//get new selected date
DateTime theNewTime = toAccess.SelectedDate;

//set the textbox to show the new date
toShow.Text = theNewTime.ToString();

//test code to verify results
Response.Write(toShow.Text);
}

When I change the selection in the Calendar I can obtain the new value
fine, find the TextBox control fine, set the TextBox.Text property
fine and the print statement prints the value that should end up in
the TextBox. The problem is that the value never shows up in the
TextBox.

I think my problem might be in the sequence of events for an ASP.NET
page. Can anyone either provide a better way to access a control that
is in a FormView or suggest a whole different approach? Thanks.
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top