Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

I have a page which displays the dates on a calendar which are picked from the database.

For eg: If in the particular table, we have 3rd,4th and 5th March inserted. On the page, 3rd,4th and 5th March will be colored in red. Now I want to add another functionality to the calendar. I want every time anybody clicks on the respective dates, an alert dialog box should pop up with some data in it.

Can you please help me with the same, I am new to ASP.NET.
Posted

According to this, http://forums.asp.net/t/1581880.aspx?+asp+Calendar+how+to+handle+OnClick+on+client+side+[^], it can't be done with this control.

However, if you know jQuery you may be able to do it. Run the calendar and then view the source and see if the dates all have a certain class or id and then you could use jquery to wire up a click event on them.
 
Share this answer
 
Comments
Shivangi_K 10-Mar-15 7:51am    
Every individual date does not have an ID. Is there a way I can check that? Can you send me a tutorial or a link as to how can I wire up an onclick event using Jquery in my aspx page.
Shivangi_K 10-Mar-15 7:54am    
Will adding a label control along with text help to give me, if not exactly the same but similar result?

sample code given below:

string aHoliday;
DateTime theDate = e.Day.Date;
aHoliday = holidays[theDate.Month, theDate.Day];
if (aHoliday != null)
{
Label aLabel = new Label();
aLabel.Text = " <br>" + aHoliday;
e.Cell.Controls.Add(aLabel);
}
ZurdoDev 10-Mar-15 8:05am    
Yes, if you can add something to each cell then you can hook up to that.
Shivangi_K 10-Mar-15 8:10am    
I tried this it is working but it gives me a very rough look, as in it adds the text along with the date. I am pretty sure there must be a better way to implement this.
I have gotten a better way to do it. I added a tooltip in the cell controls of the calendar and now, instead of an alert box, I am getting my text when we hover the mouse over the date.

Code that I used below:

e.Cell.ToolTip = "hello Today is a holiday";

Added this command in the protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) function.

Looks like a better solution to me... However, more suggestions are still welcome :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900