Calendar onselectionchanged problem

  • Thread starter Thread starter Trond
  • Start date Start date
T

Trond

I'm having problem with the onselectionchanged event. I won't fire.
Nothing happens when I select a day. That means, the page is posted
back, but the test-string is not written. My Page_Load function is
empty and the calendar renders just fine. Here's my code:


usercalendar.SelectionChanged += new
EventHandler(this.Calendar_selectday);
PlaceHolder1.Controls.Add(usercalendar);


public void Calendar_selectday(object sender, System.EventArgs
e)
{
Response.Write("Test");
}
 
Thanks for your reply Ethem. But you can't set autopostback true/false
on calendarobjects, can you?
Anyway, the page gets postbacked when selecting a date, but the event
and hence my eventhandler function doesn't run.
 
Just for kicks, try adding a <div id='msg/> to your aspx page and in your
Calendar_selectday, set msg="Test";
does that work?
 
Thanks for the suggestion, but it didn't work. It seems like it never
hits the Calendar_selectday-function...
 
Sorry, maybe I'm getting you wrong. Are you creating the calendar on runtime
and adding it to the placeholder? Problem can be that you don't create the
calendar on each postback and add the event to it. In this case, the event
binding will get lost. Try this;

protected PlaceHolder plHolder;
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
protected Calendar cal;
private void Page_Load(object sender, System.EventArgs e)
{
cal = new Calendar();
cal.SelectionChanged +=new EventHandler(cal_SelectionChanged);
plHolder.Controls.Add(cal);
}


private void cal_SelectionChanged(object sender, EventArgs e)
{
Response.Output.Write(cal.SelectedDate.ToString());
}

I tested and it works.

Hope this works,

Ethem
 
Thanks again for the replies!

I sorted it out. The problem was that my binding of the
eventhandler(selectionchanged) was done to late in the page cycle. I
moved it into the Page_Load function and then it worked!

Thanks again!

...Trond
 
Back
Top