Select calendar date problem in formview.
-
Sorry - this is a repost - forgot to ignore html tags. I want to embed a calendar in my a formview and pick a date from it which will be assigned to a textbox. I have a linkbutton to the initially hidden Calendar which set the mode of the Calendar to visible. OK so far. I next want to pick a date from the Calendar but so far have been unable to assign the selected date to the textbox. The errors I get are w.r.t the Calendar1_SelectionChanged method. 1. the object validToDate does not contain a definition for 'text' 2. the object cal does not contain a definition for 'SelectedDate' Here's my code: protected void Calendar1_SelectionChanged(object sender, EventArgs e) { object validToDate =null; validToDate = FormView1.FindControl("ValidToTextBox"); object cal=null; cal = FormView1FindControl("Calendar1"); validToDate.text= clnd.SelectedDate.ToShortDateString(); FormView1.FindControl("Calendar1").Visible = false; } protected void linkButton1_Click(object sender, EventArgs e) { FormView1.FindControl("Calendar1").Visible = true; }
-
Sorry - this is a repost - forgot to ignore html tags. I want to embed a calendar in my a formview and pick a date from it which will be assigned to a textbox. I have a linkbutton to the initially hidden Calendar which set the mode of the Calendar to visible. OK so far. I next want to pick a date from the Calendar but so far have been unable to assign the selected date to the textbox. The errors I get are w.r.t the Calendar1_SelectionChanged method. 1. the object validToDate does not contain a definition for 'text' 2. the object cal does not contain a definition for 'SelectedDate' Here's my code: protected void Calendar1_SelectionChanged(object sender, EventArgs e) { object validToDate =null; validToDate = FormView1.FindControl("ValidToTextBox"); object cal=null; cal = FormView1FindControl("Calendar1"); validToDate.text= clnd.SelectedDate.ToShortDateString(); FormView1.FindControl("Calendar1").Visible = false; } protected void linkButton1_Click(object sender, EventArgs e) { FormView1.FindControl("Calendar1").Visible = true; }
I noticed you are using a lot of FindControls, which I don't think you need. Try this for your
Calendar1_SelectionChanged()
function:protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{ ValidToTextBox.Text= Calendar1.SelectedDate.ToShortDateString(); Calendar1.Visible = false; }
-
I noticed you are using a lot of FindControls, which I don't think you need. Try this for your
Calendar1_SelectionChanged()
function:protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{ ValidToTextBox.Text= Calendar1.SelectedDate.ToShortDateString(); Calendar1.Visible = false; }
Mike Ellison wrote:
I noticed you are using a lot of FindControls, which I don't think you need. Try this for your Calendar1_SelectionChanged() function: protected void Calendar1_SelectionChanged(object sender, EventArgs e) { ValidToTextBox.Text= Calendar1.SelectedDate.ToShortDateString(); Calendar1.Visible = false; }
Yes - you do need to use FindControl to find a control in FormView or DetailsView etc. That will work outside the FormView. Anyway I've figured it out. protected void Calendar1_SelectionChanged(object sender, EventArgs e) { TextBox validToDate; Calendar cal; validToDate=(TextBox)FormView1.FindControl("ValidToTextBox"); cal = (Calendar)FormView1.FindControl("Calendar1"); validToDate.Text = cal.SelectedDate.ToShortDateString(); FormView1.FindControl("Calendar1").Visible = false; } Perhaps there's a neater or better way as I'm pretty new to this. But it works. Maj
-
Mike Ellison wrote:
I noticed you are using a lot of FindControls, which I don't think you need. Try this for your Calendar1_SelectionChanged() function: protected void Calendar1_SelectionChanged(object sender, EventArgs e) { ValidToTextBox.Text= Calendar1.SelectedDate.ToShortDateString(); Calendar1.Visible = false; }
Yes - you do need to use FindControl to find a control in FormView or DetailsView etc. That will work outside the FormView. Anyway I've figured it out. protected void Calendar1_SelectionChanged(object sender, EventArgs e) { TextBox validToDate; Calendar cal; validToDate=(TextBox)FormView1.FindControl("ValidToTextBox"); cal = (Calendar)FormView1.FindControl("Calendar1"); validToDate.Text = cal.SelectedDate.ToShortDateString(); FormView1.FindControl("Calendar1").Visible = false; } Perhaps there's a neater or better way as I'm pretty new to this. But it works. Maj
Oh - I got it. I missed the FormView part.