Calendar onselectionchanged problem

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");
}
 
T

Trond Wahlstrom

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.
 
G

Girish bharadwaj

Just for kicks, try adding a <div id='msg/> to your aspx page and in your
Calendar_selectday, set msg="Test";
does that work?
 
T

Trond Wahlstrom

Thanks for the suggestion, but it didn't work. It seems like it never
hits the Calendar_selectday-function...
 
G

Guest

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
 
T

Trond Wahlstrom

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top