I'm using DayPilot Calendar and Navigator on Visual Studios 2013, webform.
I am able to link the navigator to the calendar, so when I click on a different week, it reflects on the calendar as well.
Problem is, when i select a different week, all my data in the calendar is gone, and the week I click on is not updated in the calendar.
I tried changing the properties for the Calendar to postback/callback but it still doesn't work.
However, my Navigator is able to retain the data when I select a different week.
This is when i first debug the webform.
And this is when i click on the Navigator (the calendar at the bottom). As shown, the data is gone.
How do i solve this problem?
-- You can see that the navigator retains the data shown by the date in bold.
These are the codes I've used.
protected void DayPilotCalendar1_Command (object sender, DayPilot.Web.Ui.Events.CommandEventArgs e)
{
switch (e.Command)
{
case "navigate":
DateTime start = (DateTime)e.Data["EventStart"];
DateTime end = (DateTime) e.Data["EventEnd"];
DayPilotCalendar1.StartDate = start;
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
break;
}
}
You need to reload the event data as well:
protected void DayPilotCalendar1_Command (object sender, DayPilot.Web.Ui.Events.CommandEventArgs e)
{
switch (e.Command)
{
case "navigate":
DateTime start = (DateTime)e.Data["EventStart"];
DateTime end = (DateTime) e.Data["EventEnd"];
DayPilotCalendar1.StartDate = start;
DayPilotCalendar1.DataSource = LoadYourEventsHere(); // load data
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
break;
}
}
This is the missing part:
DayPilotCalendar1.DataSource = LoadYourEventsHere(); // load data
Related
I've been searching for a couple of days now and am running into an issue no matter what I've tried. The problem is that I seem to have come across with the perfect storm and I can't get all 3 things working at the same time.
Pagination
Optional Parameters
Parameter Dialog Prompt
So this first method is what I've been using and everything works except it won't Navigate past past 2 (And I've very aware of why navigation doesn't work)
// ##################################################################################################################################################
// METHOD 1: Everything works correctly except you can't go past page 2
protected void Page_Load(object sender, EventArgs e)
{
CrystalReportViewer1.ReportSource = Session["myReportDoc"] as CrystalDecisions.CrystalReports.Engine.ReportDocument;
if (CrystalReportViewer1.ReportSource == null)
{
//Generate the Report Document
Handlers.ReportHandler myReportHandler = new Handlers.ReportHandler();
CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument = myReportHandler.GenerateReport("AlarmStatusReport");
Session["myReportDoc"] = myReportDocument; //This is were we save it off for next time
CrystalReportViewer1.ReportSource = myReportDocument;
}
}
So knowing that the common fix is to not use Page Load but use Page_Init instead. This fixes the Navigation... until I open a report that has optional parameters. With those, every time I try to navigate to the next page, instead of it working, the Parameter box re-appears and now requires at least 1 of my Optional Parameters to be filled out. (Each "next Page" reduces the prompt by 1 Optional). But, because I'm being forced to change the Parameters, it "refreshes" the report and I'm back on Page 1.
// ##################################################################################################################################################
// METHOD 2: Works, but not for any report that has Optional Parameters. They become "Required" and keep popping up instead of navigating to the next page
protected void Page_Init(object sender, EventArgs e)
{
CrystalReportViewer1.ReportSource = Session["myReportDoc"] as CrystalDecisions.CrystalReports.Engine.ReportDocument;
if (CrystalReportViewer1.ReportSource == null)
{
//Generate the Report Document
Handlers.ReportHandler myReportHandler = new Handlers.ReportHandler();
CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument = myReportHandler.GenerateReport("AlarmStatusReport");
Session["myReportDoc"] = myReportDocument; //This is were we save it off for next time
CrystalReportViewer1.ReportSource = myReportDocument;
}
}
Now, I got real excited, because I got a bit clever and fixed both those issues, by trapping the Navigation and keeping track of the Page myself. EVERYTHING WORKS NOW!!! until I go to the Parameter Dialog prompt and it was totally jacked up.
// ##################################################################################################################################################
// METHOD 3: Everything works correctly except the Prompt Box doesn't Format correcly due to the addition of the added Event Handers
protected void Page_Load(object sender, EventArgs e)
{
CrystalReportViewer1.ReportSource = Session["myReportDoc"] as CrystalDecisions.CrystalReports.Engine.ReportDocument;
if (CrystalReportViewer1.ReportSource == null)
{
//Generate the Report Document
Handlers.ReportHandler myReportHandler = new Handlers.ReportHandler();
CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument = myReportHandler.GenerateReport("AlarmStatusReport");
Session["myReportDoc"] = myReportDocument; //This is were we save it off for next time
CrystalReportViewer1.ReportSource = myReportDocument;
//Init our Manual Page Counter to 1
HiddenFieldPageNumber.Value = "1";
}
CrystalReportViewer1.Navigate += CrystalReportViewer1_Navigate; //Simply Adding this event, EVEN IF IT HAS NO CODE, Breaks the style and formating of the Parameter Prompt box.
CrystalReportViewer1.PreRender += CrystalReportViewer1_PreRender;
}
private void CrystalReportViewer1_Navigate(object source, CrystalDecisions.Web.NavigateEventArgs e)
{
//This prevents this event from Incrementing the Page again when the PreRender Event
//below re-sets which page to show.
if (_SkipPageIncrement == true)
{
return;
}
//Whenever the Navigation is used, this Event fires. Here is the problem, there is nothing that actually tells
//us if the user clicked on Previous or Next (or GotoPage for that Matter). So we have to do some guessing here
if (e.CurrentPageNumber == 1 && e.NewPageNumber == 2)
{
//If they pressed "NEXT" we will always get Current = 1 and New = 2 due to the Pagination starting over on the PostBack
//So we INCREMENT our real Page Number Value.
HiddenFieldPageNumber.Value = (Convert.ToInt32(HiddenFieldPageNumber.Value) + 1).ToString();
}
else if (e.CurrentPageNumber == 1 && e.NewPageNumber == 1)
{
//If they pressed "PREV" we will always get Current = 1 and New = 1 due to the Pagination starting over on the PostBack
//So we DECREMENT our real Page Number Value.
HiddenFieldPageNumber.Value = (Convert.ToInt32(HiddenFieldPageNumber.Value) - 1).ToString();
}
}
private void CrystalReportViewer1_PreRender(object sender, EventArgs e)
{
//The Viewer has a method that allows us to set the page number. This PreRender Event is the only
//Event I could find that works. It comes AFTER the Navigate, but before the reports is rendered.
_SkipPageIncrement = true; //The ShowNthPage re-triggers the Navigation, so this prevents it from running again.
CrystalReportViewer1.ShowNthPage(Convert.ToInt32(HiddenFieldPageNumber.Value));
}
As commented above, the moment I add the OnNavigation Event, even if I comment out all the actual code inside, my Prompt box goes from looking like this...
To this (my page as a dark background and you can see that now shows, plus the "OK" button is all jacked up.
I just don't get why trapping the Navigation Event breaks the Prompt box even when the event is not firing (on that first load).
Side note: I'm using VS 2019 with CR 13.0.3500.0
So thanks to the help of a teammate that is more adept on CSS as I am, I have resolved the issue "good enough". So for anyone who wants to use the LOAD event, (Or has to like me), but then loses the ability to use the navigation and wants to use my method, the band-aid for the Crystal Reports Parameter prompt is to simply override their Styling in you Site.css with this...
/*---------------------- Custom CSS for Report Prompt Buttons ----------------------*/
.pePromptButton {
padding-bottom:4.3px;
}
td.pePromptButton {
display: inherit;
}
img {
vertical-align:top;
}
I am using a gridview in my asp.net project to view and modify some records from the database. The database has two columns: start_date and end_date. When a new record is created these columns contains null, but they can be modified later using the gridview update command.
In gridview I have two template fields (having names start_date and end_date) in which I have placed two calendar controls. Upon clicking an update link of gridview it always returns an error because of the null value binding to the calendar. I have used this helper function to solve it:
protected DateTime ReplaceNull(Object param)
{
if (param.Equals(DBNull.Value))
{
return DateTime.Now;
}
else
{
return Convert.ToDateTime(param);
}
}
and used these two custom expressions in calendar control's SelectedDate:
ReplaceNull(Eval("start_date"))
ReplaceNull(Eval("end_date"))
The problem is that two-way data binding the calendars upon selecting a date does not update the database table. Are there any workarounds? Or alternatively, a better solution would be appreciated.
I don't know why you let them null when insert a new record , but many ways you can solve this problem i think .
one of them : in the RowDataBound event of the Gridview
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1] == null) //the index of the start_date
{
e.Row.Cells[1].Text = DateTime.Now.ToString(); // in your case you will make the selected date of the calender(through casting to calender) with the value you need.
}
}
}
Or: you can catch the exception , you meet in your Update button through
try and catch block.
I am adding to a List of DateTime objects on the server every time a date is selected on a Calender control by the client, and in turn highlighting all the selected dates on the control. I'm able to highlight (change back-color) of dates instantiated in the List on page load, and the first selected date by the client. However further date selections on the control are just changing which date is highlighted, ie. not highlighting more.
I had thought by adding the selected DateTime object to a list at runtime upon a selection and then adding each of them to the Calendars "selected dates" property will get around the problem of the calendar control clearing the SelectedDates property on selection of a new date. Debugging by printing all the dates within the dates List to a textbox show that the dates the list was instantiated with and the latest selection are only in the list, not previous selections. My question and what I think is the problem,
Can a List on the server be populated by actions from the client at runtime, and added to?
I am using ASP with C# .Net3.5 on VS2008.
Thanks
My Code
System.Collections.Generic.List dates;
protected void Page_Load(object sender, EventArgs e) {
this.dates = new List<DateTime>();
this.dates.Add(new DateTime(2009,12,2));
this.dates.Add(new DateTime(2009, 12, 3));
this.dates.Add(new DateTime(2009, 12, 16));
fillDates();
}
protected void AvailCalender_SelectionChanged(object sender, EventArgs e){
this.dates.Add(this.AvailCalender.SelectedDate);
foreach (DateTime date in this.dates)
{
this.AvailCalender.SelectedDates.Add(date);
this.displayText.Text = this.displayText.Text + date.ToShortDateString();
}
fillDates();
}
protected void fillDates()
{
foreach (DateTime dates in this.dates)
{
this.AvailCalender.SelectedDates.Add(dates);
}
this.AvailCalender.SelectedDayStyle.BackColor = System.Drawing.Color.Blue;
}
The List<DateTime> is getting created with each postback so it is not saving the previous selections. You need to persist it in some way like using ViewState, Session or storing it in a DB. Only create it the first time by using Page.IsPostBack to check if this is the first time the page has been hit.
I am developing an online exam application using asp.net. In the start exam page I have created a javascript countdown timer.
How can I move to the next page automatically after the timer reaches 00?
Here is my code:
long timerStartValue = 1000 ;
private int TimerInterval
{
get
{
int o =(int) ViewState["timerInterval"];
if(o==0)
{
return (o);
}
return 50 ;
}
set
{
ViewState["timerInterval"] = value;
}
}
protected void Page_PreInit(object sender,EventArgs e)
{
string timerVal = Request.Form["timerData"];
if(! String.IsNullOrEmpty(timerVal))
{
timerVal = timerVal.Replace(",", String.Empty) ;
this.timerStartValue = long.Parse(timerVal);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(! IsPostBack)
{
this.timerStartValue = 10000; //3599000;//14400000;
this.TimerInterval = 500;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.timerStartValue = 3599000;
}
protected void Page_PreRender(object sender, EventArgs e)
{
System.Text.StringBuilder bldr=new System.Text.StringBuilder();
bldr.AppendFormat("var Timer = new myTimer({0},{1},'{2}','timerData');", this.timerStartValue, this.TimerInterval, this.lblTimerCount.ClientID);
bldr.Append("Timer.go()");
ClientScript.RegisterStartupScript(this.GetType(), "TimerScript", bldr.ToString(), true);
ClientScript.RegisterHiddenField("timerData", timerStartValue.ToString());
}
Thanks in advance,
sangita
It sounds like when you click the "Next" button, you are loading an entirely new page. This of course changes all the content and resets all the javascript. You can't maintain state across pages without a bit of work.
The solution to this could be to save the timer state when the next button is pressed, and pass it to the next stage. You could do this by saving the timer state to a hidden form input and submitting it along with the Next button.
The other option would be to load your questions via AJAX. Instead of moving to a new page every time the next button is clicked, you could simply replace the question portion of the page with a new question, and leave the timer intact. This is probably the solution I would use.
Are u reloading the entire page when clicking on the next button ? That may leads to realod the java script file also.So the variable values will reset.May be you can think about showing the questions /answers via Ajax.You need not reload the entire page when showing the next question.the part when you show the quiz will only be updated.so you can maintain the global variables in your java script too. Check the below link to know about partial page updating using jQuery.
http://www.west-wind.com/presentations/jquery/jquerypart2.aspx
Hope this helps.
You can put the timer in an iframe if you can't get rid of the postback.
You need a way to persist information between pages, and there's really only one possibility: To make it part of the next page request.
Now, this could be subdivided into 2 categories:
1) As part of the url: http://www.example.com/page?timer=123;
2) As part of the headers;
And number 2 opens new possibilities:
a) As part of POST data;
b) As a client-side cookie only;
c) As a cookie tied to information on the server;
Number 1, 2a and 2b can be manipulated by the user. So what you can do is store some value in a cookie, a hash for example or a database row ID, that you'll use to fetch information on the server.
tl;dr? Use a asp "Session object". It lets you keep things on the server-side and users will have no idea what they are.
I have code to do multiple selections in a calendar control but I would like to change the color of the initially selected day to green and the end date to red. Visually this would indicate the start date and end date of a certain service to be
provided. Should I be looking into RenderControl Method for my calander or more looking into setting some attribute of the days in the control?
The multiple select code is attributable to
Steve Wellins
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
System.Web.UI.WebControls.Calendar TheCalendar = sender as System.Web.UI.WebControls.Calendar;
// create new list of dates or get stored list of dates
List SelectedDates;
if (ViewState["SelectedDates"] == null)
SelectedDates = new List();
else
SelectedDates = ViewState["SelectedDates"] as List;
// if date is already in list, remove it, otherwise, add it
if (SelectedDates.Contains(TheCalendar.SelectedDate) == false)
SelectedDates.Add(Calendar1.SelectedDate);
else
SelectedDates.Remove(Calendar1.SelectedDate);
// set the calendar to our list of dates
TheCalendar.SelectedDates.Clear();
foreach (DateTime Date in SelectedDates)
TheCalendar.SelectedDates.Add(Date);
// store list for next postback
ViewState["SelectedDates"] = SelectedDates;
}
This code may overwrite any date or formatting applied to the calendar but I am not above saving and restoring this formating to the calendar.
foreach (DateTime Date in SelectedDates)
TheCalendar.SelectedDates.Add(Date);
I am glad to research leads if you point me down the right path or terms to search for.
From the MSDN site the Calendar..::.OnDayRender Method is invoked while each day is being rendered. I am a .NET noob... how to use it all?