Customize the ASP. NET calendar control as needed (customize the ASP. NET calendar Control)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.