[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Modify calendar control to allow user input?

Posted on 2009-12-28
26
Medium Priority
?
428 Views
Last Modified: 2012-05-08
Hello Experts

I need to build a calendar app that allows my web users to enter in a value for each day of the month.  This allows them to easily use the calendar to enter in which days are full days (1), half days (.5), and closed days (0).  That way I can report off of how many days they are actually open for business.  I like the asp:calendar just fine, so is there some way to enhance it a bit to show a list of checkboxes when a user clicks on a particular day?  Just need a quick popup that shows the 3 choices for that day.  Help!
0
Comment
Question by:jay-are
  • 15
  • 11
26 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26131837
yes, on the dayrender event, add a text box, but have it be invisible

then on the selected event, make the textbox visible...
0
 
LVL 21

Expert Comment

by:silemone
ID: 26131870
or on the dayrender, add a textbox and a edit linkbutton and a save button...

when they click the edit button  the other two textbox and save button shows...



and finally, just create a database that has those days that are half days and closed days and they won't have to edit it themselves...it can just load off of the db using again the dayrender event...it will check date = date in db, if it does it will get value or either 5 or 0, otherwise if there is nothing in the db for that day, mark the cell with 1
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132027
scratch this:

or on the dayrender, add a textbox and a edit linkbutton and a save button...
when they click the edit button  the other two textbox and save button shows...

since the dates themselves are already linkbutton and have selectionchanged, just sick with either

1) yes, on the dayrender event, add a text box, but have it be invisible
then on the selected event, make the textbox visible...you will have to save immediately after text changed using text box event...

or

2) just create a database that has those days that are half days and closed days and they won't have to edit it themselves...it can just load off of the db using again the dayrender event...it will check date = date in db, if it does it will get value or either 5 or 0, otherwise if there is nothing in the db for that day, mark the cell with 1

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jay-are
ID: 26132074
I was hoping for something even simpler for the user like a checkbox so the data doesn't rely on them entering the correct day value (insted of entering 1 for full day they could enter 2 accidentally).  I could make each checkbox value either 1, .5, or 0 depending on the checkbox...I've figured out how to add the control when I pick a day.  So all I really need is a table for each month now.

I'll put in default values for each month based on what I think are full/half/closed days.  
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132184
good...you're pretty much there...

so you have a checkboxlist

on checkchanged event you save to the database immediately, yes?  otherwise where will you be saving at?
0
 

Author Comment

by:jay-are
ID: 26132221
What's the best way to do this?  3 checkboxes or 1 checkbox list?  I have to progmatically set the value of these checkboxes somehow.  I'm stuck on that right now.  Once they make their selection I think a simple "save" or "update" button will save the value to a table.  I'll just have to setup a table for each month of the year I guess?
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132281
checkboxlist would be ideal...this works more like radio buttons where there can only be one checked box within the group...

0
 
LVL 21

Expert Comment

by:silemone
ID: 26132325
tables - i would just save dates that are other than fullday to the db since most days will be full days...so if someone choses fullday checkbox, my call to the db would be to delete the row from the table...this makes your db smaller than adding each day of the year...
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132343
so basically

add to the db if the half-day or closed.  
otherwise if the calendar day does not exist in the db, then it should have checkedbox fullday checked...

if a value is changed to a fullday, then remove it from the table to keep the above logic.
0
 

Author Comment

by:jay-are
ID: 26132670
Ok I'm having trouble with the checkboxlist and adding the 3 items I want - Full, Half, Closed and then assigning a value to each of those items.  How do I do this in the code-behind?
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132698

          protected void cal_DayRender(object sender, DayRenderEventArgs e)
        {

            CheckBoxList chkbox = new CheckBoxList();
            chkbox.Items.Add(new ListItem("check1", "one", true));
            chkbox.Items.Add(new ListItem("check2", "two", true));


           
            e.Cell.Controls.Add(chkbox);
           
        }

Open in new window

0
 
LVL 21

Expert Comment

by:silemone
ID: 26132708
Specifically for you code...
protected void cal_DayRender(object sender, DayRenderEventArgs e)
        {

            CheckBoxList chkbox = new CheckBoxList();
            chkbox.Items.Add(new ListItem("Full", "1", true));
            chkbox.Items.Add(new ListItem("Half", ".5", true));
            chkbox.Items.Add(new ListItem("Closed", "0", true));


           
            e.Cell.Controls.Add(chkbox);
           
        }

Open in new window

0
 

Author Comment

by:jay-are
ID: 26133095
Ok how do I get the CBL to postback?  When I click one of the 3 selections it isn't posting back.  I have tried
cb1.AutoPostBack = True in the load event and everywhere else as well and it still won't postback.
0
 
LVL 21

Expert Comment

by:silemone
ID: 26133163
ouch - just found this:

Generally, the ASP.NET web page will process the postback events after page
load .. before page's PreRender event. So We must register the event
handler no late than Page_load.
So for your scenario, you add the dynamic created Usercontrol in the
calendar's DayRender event(I admit that this is the only availble one we
can make use of for the current ASP.NET buildin Calendar) which is after
page processing the postback event, so the postback event of the sub
controls (we added dynamically in DayRender) won't be fired.
So currently for the ASP.NET buildin Calendar control, the dayRender event
is capable of helping adding some display only controls, for those ones
which also need post back event handling, I'm afraid, we may need to look
for some other Calendar controls or implemet a custom one.

what version of .net are you using?
0
 
LVL 21

Expert Comment

by:silemone
ID: 26133170
ouch - just found this from ms forum:

Generally, the ASP.NET web page will process the postback events after page
load .. before page's PreRender event. So We must register the event
handler no late than Page_load.
So for your scenario, you add the dynamic created Usercontrol in the
calendar's DayRender event(I admit that this is the only availble one we
can make use of for the current ASP.NET buildin Calendar) which is after
page processing the postback event, so the postback event of the sub
controls (we added dynamically in DayRender) won't be fired.
So currently for the ASP.NET buildin Calendar control, the dayRender event
is capable of helping adding some display only controls, for those ones
which also need post back event handling, I'm afraid, we may need to look
for some other Calendar controls or implemet a custom one.

Thanks,
Steven Cheng
Microsoft Online Support
0
 

Author Comment

by:jay-are
ID: 26133181
blah, I knew the built in asp calendar would be too good to be true...I'm using 2.0 right now.  The postback isn't a huge issue I guess.  I was really trying to test before I wrote the code to update a db table.  
0
 

Author Comment

by:jay-are
ID: 26133195
Shouldn't I just add a button that will actually get the values of the checkboxlist and update the table?  I can check pre-update to see if they checked multiple boxes and stop...
0
 
LVL 21

Accepted Solution

by:
silemone earned 2000 total points
ID: 26133308
it wouldn't work sorry to say unless you don't postback on the selectionchanged - if you call that, then all the values will revert back to their original values since the page has essentially been refreshed...

if you add a button, then you couldn't refresh the calendar (i.e call any events on it) til you pressed the button and that would irritate a lot of people...

I suggest a 2 part scenario...

1) you click on a day and a hidden panel is shown with 3 check boxes and a save button (or modal popup)...this part will add value to db as we discussed before...only adding value that aren't full days...if the value is already in the db, then you will remove the row (because that means it was a .5 or 0), so in your Stored Procedure, you must first see if the date exists and depending on the value, remove it or update it...

then

2)  just load off of the db using again the dayrender event...it will check date = date in db, if it does it will get value or either 5 or 0, otherwise if there is nothing in the db for that day, mark the cell with 1


0
 

Author Comment

by:jay-are
ID: 26133560
How will the hidden panel or checkboxlist know which day called?
0
 
LVL 21

Expert Comment

by:silemone
ID: 26133819
there's always the object source, eventArgs e that can be passed as params...
0
 

Author Comment

by:jay-are
ID: 26134168
Ok I'm not sure what to do now.  I added a checkboxlist to the page next to the calendar along with a button.  Same setup that we used inside the calendar control, just outside of it.  When I select a day and the checkboxlist/button appear next to the calendar I can't click the button and get any values since the page posts back.  Ideas?
0
 

Author Comment

by:jay-are
ID: 26134241
Ah wait, I was still setting up the listitems inside the DayRender event...Once I moved those to page_load it is now giving me the correct values.
0
 
LVL 21

Expert Comment

by:silemone
ID: 26134400
awesome
0
 

Author Comment

by:jay-are
ID: 26134502
Now I'm having trouble getting the value of the day/month/year that is selected...Obviously I can just hardcode month/year since I'm only going to use current month.  I just need the value for the day though.
0
 
LVL 21

Expert Comment

by:silemone
ID: 26137483
the Calendar argument (e) will have that....

e.Cell...
e.Day...

that's why i said you would have to pass your params...it will give you what day was called,etc...
0
 

Author Comment

by:jay-are
ID: 26137715
You are right.  I can get the date now.  I think you've given me enough info now to complete this!  Thank you so much!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question