strange behaviour of DayRender event

g_r_a_robinson

Regular
Joined
Jan 13, 2004
Messages
71
I have a calendar control that I am able to add certain items (tasks, lunchs etc) . When I click the save button it adds my new task as expected. But if I go to add another it removes the previously added task, in fact it removes all of the previously added tasks except the one just added. I have deliberately not use a IsPostBack method because I need it to render/rebind everytime a change is made to the calendar.

I can click the calendar link and see all of my tasks at once, the bahaviour emntioned above only happens when I add a new event.

Heres my code:


<code>
private void Page_Load(object sender, System.EventArgs e)
{
String prefix = PathPrefix;

Calendar_Manager_PNL.BackImageUrl = prefix + "/images/mini_Calendar_Back.gif";

jobSystem = new JobSystem();
jobData = jobSystem.GetAllEvents();
jobView = jobData.Tables[JobData.JOBS_TABLE].DefaultView;

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Submit_to_calendar_BTN.Click += new System.EventHandler(this.Submit_to_calendar_BTN_Click);
this.cancel_BTN.Click += new System.EventHandler(this.cancel_BTN_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public void eventscalendar_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
//use a StringBuilder object for optimized string concatenation
StringBuilder strEvents = new StringBuilder();
strEvents.Append("<span style=\"font-size:80%\">");

foreach (DataRow row in jobData.Tables[JobData.JOBS_TABLE].Rows)
{
String test = row[JobData.CONTACTS_FIELD].ToString();
if(row[JobData.CONTACTS_FIELD].ToString() == "null")
{
DateTime eventdate = Convert.ToDateTime(row[JobData.DUE_DATE_FIELD]);
DateTime Start_Time = Convert.ToDateTime(row[JobData.START_TIME_FOR_FREE_FIELD]);
String due_Start_Time_String = Start_Time.ToShortTimeString();
DateTime Finish_Time = Convert.ToDateTime(row[JobData.FINISH_TIME_FOR_FREE_FIELD]);
String due_Finish_Time_String = Finish_Time.ToShortTimeString();
String JobTitle = row[JobData.JOB_TITLE_FIELD].ToString();
String JobNo = row[JobData.JOB_ID_FIELD].ToString();

if (eventdate.Equals(e.Day.Date))
strEvents.Append("<br />" + due_Start_Time_String + "<br />" + due_Finish_Time_String + "<br>" + JobTitle + "<br>" + JobNo + "<br><br>");

}

else
{
DateTime eventdate = Convert.ToDateTime(row[JobData.DUE_DATE_FIELD]);
DateTime dueTime = Convert.ToDateTime(row[JobData.DUE_TIME_FIELD]);
String dueTimeString = dueTime.ToShortTimeString();
String Consultant = row[JobData.BY_WHO_NAME_FIELD].ToString();
String Client = row[JobData.CONTACTS_FIELD].ToString();
String JobTitle = row[JobData.JOB_TITLE_FIELD].ToString();
String JobNo = row[JobData.JOB_ID_FIELD].ToString();

if (eventdate.Equals(e.Day.Date))
strEvents.Append("<br />" + dueTimeString + "<br />" + Consultant + "<br>" + Client + "<br>" + JobTitle + "<br>" + JobNo + "<br><br>");
}

}

//Close off the string in the strEvents StringBuilder
strEvents.Append("</span>");

//Add the string to the cell in a LiteralControl
e.Cell.Controls.Add(new LiteralControl(strEvents.ToString()));

}

private void Submit_to_calendar_BTN_Click(object sender, System.EventArgs e)
{
//DataRow clientsRow;

bool valid = true;
bool retVal;

ArrayList arraylist = new ArrayList();

// Insert the userID
int userID = links.UserID;

int clientID = 0;
String Action_DD = "null";
int User_ByWho = 0;
String User_ByWhoName = "null";
int profileID = 0;
String Search_LB = "null";

// Insert the Due date into the new row
String CalendarDate = CalendarPopup1.SelectedDate.ToShortDateString();

String dueTime = "12:00";

String completedCheckedBy = "null";
String Authorisation = "null";

String Start_Time_For_Free = From_TMP.SelectedTime.ToShortTimeString();
String Finish_Time_For_Free = To_TMP.SelectedTime.ToShortTimeString();

if (valid == true)
{
retVal = (new JobSystem()).CreateJob(//jobID,
arraylist, // don't need
userID,
clientID, // don't need
profileID, // don't need
Free_Description_TBX.Text,
Search_LB, // don't need
CalendarDate,
dueTime, // don't need
Action_DD, // don't need
User_ByWho, // don't need
User_ByWhoName, // don't need
completedCheckedBy, // don't need
Authorisation, // dont need
Start_Time_For_Free,
Finish_Time_For_Free,
out jobData);

// eventscalendar_DayRender("renderAgain", new System.Web.UI.WebControls.DayRenderEventArgs());

// Session["JobID_By_Session"] = JobSystem.JobIDforDefault;
// JobWithNoteViewer.JobViewMessage = null;

// defaultNoteAdd = "editForDefault"; //xyz
// Response.Redirect(PageBase.SecureUrlBase + @"/secure/NoteScreen.aspx", true); //xyz this was originally jobScreen
}
else
{
}
}
</code>

also I have the
<code>
OnDayRender="eventscalendar_DayRender"
</code>

event in my html
 
Back
Top