calendar problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,
I have a problem with a calendar control. I put the following function in
the SelectionChanged event

public void DatePick(object sender, System.EventArgs e)
{
TxtDate.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
}

I open and close the calendar with this function:

public void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Calendar1.Visible = (Calendar1.Visible == false) ? (true) : (false);
}

The problem is if the user selects the same day which has been previously
selcted the Calendar will not disappear, because the selection has not
changed. How could I make the Calendar disappear when the user selects the
same day? Putting code in the Page.IsPostBack event does not do the trick..

Any sugestions are welcome. Thanks a lot

Chris
 
One way would be to provide a Calendar1_OnClick event override and hook
up the Calendar's Click event to fire this method.

public void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventA­rgs e)
{
if(Calendar1.SelectedDate.ToShort­DateString() ==
DateTime.Today.ToShortDateString())
{
// save date?
}
Calendar1.Visible =
(Calendar1.Visible == false) ? (true) : (false);
}
 
Unfortunately this does not do the trick. What I menat is that I can not make
the calendar "invisible" when someone clicks on the same day which has been
selected before.

Chris
 
Chris,

Sorry, are you sure that you can't use it? Does the calendar not
provide a Click delegate which you can hook an Calendar1_OnClick
delegate to? I had a typo in my last post, should have been

public void Calendar1_OnClick(object sender,
System.Web.UI.ImageClickEventA­­rgs e)

rather than

public void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventA­­rgs e)

If the calendar provides this method, you can do a
Calendar1.Click += new EventHandler(Calendar1_OnClick);

Are you familiar with this type of code?
 
Back
Top