ASP Calendar - cell "OnClick" event

W

wwcoop

The calendar control allows the user to select a date by clicking
on the day number in the cell. I would like to extend
this functionality so that the use can click anywhere in a calendar
cell to trigger the selectionchanged event. I would like to assign
an "OnClick" event to the calendar cell in the OnDayRender sub.
How can I achieve the desired result?
 
W

wwcoop

Thanks, you put me on the right path. Here is the solution:
******************************************
Dim d as CalendarDay
Dim c as TableCell
Dim datOrigin as Date = "1-1-2000"
Dim strDay as String

d = e.Day
c = e.Cell

strDay = CStr(DateDiff("d", datOrigin, d.date))

.....

c.Attributes.Add("OnClick", "javascript:__doPostBack('ca','" & strDay &
"')")
******************************************
--
Will Cooper
Application Programmer


Peter Blum said:
Hi Will,

Here's a thought. The OnDayRender method is passed a TableCell control,
where you populate it with other controls. In this case, you want to add the
onclick event directly to the TableCell. The code for this is a post back,
which you use the Page.GetPostBackEventReference() method to generate the
right code. The trick is to generate the same elements in
GetPostBackEventReference() that the hyperlink on the day number does. That
takes some review of the HTML output to see what they do.

cell.Attributes.Add("onclick", Page.GetPostBackEventReference(cell, "???",
"???"))

Another approach is to replace the ASP.NET calendar with one built by a
third party that does not require post back. These calendars use javascript
and usually handle the onclick event on a day cell for you. Mine, the
CS_Calendar control inside of "Peter's Date Package"
(http://www.peterblum.com/datecontrols/home.aspx), can still optionally post
back. By using javascript, even if you elect to post back on each selection
change, you don't need to post back as the user changes months.

You will find other third party calendars at the www.asp.net control
gallery, www.411asp.net, and www.123aspx.com.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top