FormView problems

Discussion in 'ASP .Net' started by justin, Aug 3, 2007.

  1. justin

    justin Guest

    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.
    justin, Aug 3, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jéjé
    Replies:
    3
    Views:
    4,309
    Jéjé
    Oct 13, 2005
  2. Formview Problems

    , Jan 6, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    590
  3. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    521
    Chris
    May 19, 2007
  4. Enigma Boy
    Replies:
    0
    Views:
    326
    Enigma Boy
    Aug 6, 2007
  5. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    637
    David Thielen
    Jun 16, 2006
Loading...

Share This Page