Today, a variety of calendar controls fly all over the sky (see http://www.cnblogs.com/blodfox777/archive/2008/08/13/1266639.html), using ASP. net calendar Controls seem to have a few friends, but today's strange problem of a customer reminds me of one of its major advantages: You can customize as needed!
Q:
Scenario: I have a calendar control in An ASPX page and gets populated using a datasource. The data in this view is more of a title that the user can drill.
Question: I want to link the date (eg: 20) So when user clicks a client side event is fired and not a PostBack is done. how can I hook the date with a client side script?
Thanks
A:
As far as I know, If you wowould like to customize the ASP. NET calendar control, the Code shocould be written inOndayrenderEvent handle.
Just like the following demo:
When use click on a day on this calendar, instead of post back, a user definable JavaScript function will be called:
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default4.aspx. CS " Inherits = " Default4 " %>
<!Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Title > </ Title >
< Script Type = "Text/JavaScript" >
Function Clickdate (day)
{
Window. Alert (day );
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< Div > < ASP: Calendar ID = "Calendar1" Runat = "Server"
Ondayrender = "Calendar#dayrender" > </ ASP: Calendar > </ Div >
</ Div >
</ Form >
</ Body >
</ Html >
Protected Void Calendar#dayrender ( Object Sender, dayrendereventargs E)
{
E. Cell. Text= "& Lt; input type = 'button 'value ='" +E. Day. Date. Day. tostring ()+ "'Onclick = 'clickdate (this. Value); '/>";
}
for more information about ondayrender, I wocould like to suggest you to check the following link, which talks about ondayrender of calendar control.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.dayrender.aspx
If I 've misunderstood the facing issue, please feel free to let me know.
thanks.