locked
I'm having a problem Adding a date to multiple textboxes in Formview RRS feed

  • Question

  • I'm repeating this problem in this forum as it has to do with a ASP.NET.

    1-I'm basically trying to display a calendar when the formview opens in insert mode.

    2-The the user selects a date from a calendar and that date is entered into a textbox in the formview. 

    3- There are 4 different date textboxes in the formview.

    When I use my method on one text box, without having to use a switch to differentiate between the 4 different switches and textboxes there, everything seems to work.  However, while using the switch statement or an if/else loop, the routine does not work.

    It seems as if the switch statement does not work at all. Because when the Calendar fires,  the button values are wiped out when the form reloads.  I tried putting my button values in a class outside the form in the way of a property, but the same thing happens again.  The property returns a value of zero. If anybody knows how to keep those values from being reset, let me know.

    .

    public addTestPhase()

    {

    }

    string textVar="";

    const string sID1 = "PStartTextBox";

    const string sID2 = "PEndTextBox";

    const string sID3 = "ActualStartTextBox";

    const string sID4 = "ActualEndTextBox";

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

    Calendar1.Visible = true;

    textVar = "PStartTextBox";

    }

    protected void Button2_Click(object sender, EventArgs e)

    {

    Calendar1.Visible = true;

    textVar = "PEndTextBox";

    }

    protected void Button3_Click(object sender, EventArgs e)

    {

    Calendar1.Visible = true;

    textVar = "ActualStartTextBox";

    }

    protected void Button4_Click(object sender, EventArgs e)

    {

    Calendar1.Visible = true;

    textVar = "ActualEndTextBox";

    }

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {

    switch (textVar)

    {

    case sID1:

    FormViewRow row1 = FormView1.Row;

    TextBox myTextBox1 = (TextBox)row1.FindControl("PStartTextBox");

    myTextBox1.Text = Calendar1.SelectedDate.ToString("yyyy-M-d");

    break;

    case sID2:

    FormViewRow row2 = FormView1.Row;

    TextBox myTextBox2 = (TextBox)row2.FindControl("PEndTextBox");

    myTextBox2.Text = Calendar1.SelectedDate.ToString("yyyy-M-d");

    break;

    case sID3:

    FormViewRow row3 = FormView1.Row;

    TextBox myTextBox3 = (TextBox)row3.FindControl("ActualStartTextBox");

    myTextBox3.Text = Calendar1.SelectedDate.ToString("yyyy-M-d");

    break;

    case sID4:

    FormViewRow row4 = FormView1.Row;

    TextBox myTextBox4 = (TextBox)row4.FindControl("ActualEndTextBox");

    myTextBox4.Text = Calendar1.SelectedDate.ToString("yyyy-M-d");

    break;

    default:

    Calendar1.Visible = false;

    break;

    }

    }

    }

    Tuesday, July 4, 2006 3:22 PM

Answers

  • I have found a solution using a cookie and also using a session variable.

    For info about the cookie solution visit http://www.codetoad.com/asp.net/cookies.asp

    I'm about to change my code to the session variable which is similar to using a cookie, but more in line with what I'm doing.

     

    Wednesday, July 5, 2006 8:42 PM