search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Creating EventClick on a Dynamic Component Daypilot

Asked by Richard Rivière
10 years ago.

Hello, I am a problem.
I am creating dynamic component with this code:
DayPilot.Web.Ui.DayPilotCalendar d3 = new DayPilot.Web.Ui.DayPilotCalendar();

I need to create a eventclick dynamic too... but I dont know how...
I try this, but no success:
d3.EventClick += new DayPilot.Web.Ui.Events.EventClickEventHandler(DayPilotCalendar1_EventClick);

Can someone help me? Thank you.

Answer posted by Dan Letecky [DayPilot]
10 years ago.

All user actions (clicking, moving, resizing....) are disabled by default. You need to set EventClickHandling to either CallBack or PostBack in order to activate the server-side event handler.

Example:

d3.EventClickHandling = EventClickHandlingEnum.CallBack;

See also:
http://doc.daypilot.org/calendar/event-click/

Comment posted by Richard Rivière
10 years ago.

Thank you by the answer!
I put your code:
d3.EventClickHandling = DayPilot.Web.Ui.Enums.EventClickHandlingEnum.CallBack;
d3.EventClick += new DayPilot.Web.Ui.Events.EventClickEventHandler(d3_EventClick);

And now, I have this erros when I click on the Event. I think that this occours because I am working with MasterPage:

"Error!
Result: The target 'ctl00$ContentPlaceHolder$d33' for the callback could not be found or did not implement
ICallbackEventHandler.
Context: ctl00_ContentPlaceHolder1_d33"

What about you? Can you help me? Thank you!!!

Comment posted by Dan Letecky [DayPilot]
10 years ago.

Make sure that the object is created during every page load. If you don't create it during the callback request it will throw an exception like this. Also, make sure that you use the same ID every time.

Comment posted by Richard Rivière
10 years ago.

Sorry, but I dont know how to do this. Can you help me? This is my code... thank you !!!

using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using br.sistemas.ClinicaMedica;

public partial class pesquisa_agendasemana : System.Web.UI.Page
{
protected BusinessMedico BusinessMed;
protected BusinessFinanceiro BusinessFin;
protected BusinessEspecialidade BusinessEsp;
protected BusinessEmpresa BusinessEmp;
protected FuncGerais BusinessFun;

protected void Page_Load(object sender, EventArgs e)
{
BusinessEsp = new BusinessEspecialidade();
BusinessEmp = new BusinessEmpresa();
BusinessFin = new BusinessFinanceiro();
BusinessFun = new FuncGerais();
BusinessMed = new BusinessMedico();

if (!Page.IsPostBack)
{
if (Session["login"] == null)
{
Response.Redirect("login3.aspx");
}
else
{
ViewState["login"] = Session["login"].ToString();
ddEspecialidade.Enabled = false;

if (ViewState["login"].ToString() == "MESTRE")
ddUnidade.DataSource = BusinessEmp.LoadUnidade();
else
ddUnidade.DataSource = BusinessEmp.LoadUnidade(ViewState["login"].ToString(), true);
ddUnidade.DataTextField = "NOMEFANTASIA";
ddUnidade.DataValueField = "CODUNIDADE";
ddUnidade.DataBind();
FuncGerais.geraItemSelecione(ddUnidade, true);
if (ddUnidade.Items.Count == 2)
{
ddUnidade.SelectedIndex = 1;
ddUnidade_SelectedIndexChanged(ddUnidade, null);
}

ddExame.DataSource = BusinessEsp.LoadExame(true);
ddExame.DataTextField = "NOMEPROCED";
ddExame.DataValueField = "CODPROCEDIMENTO";
ddExame.DataBind();
FuncGerais.geraItemSelecione(ddExame, true);
if (ddExame.Items.Count == 2)
ddExame.SelectedIndex = 1;
}
}
}

private static DateTime firstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}
return d;
}

protected void DayPilotCalendar1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Calendar.BeforeEventRenderEventArgs e)
{
string color = e.DataItem["color"] as string;
if (!String.IsNullOrEmpty(color))
{
e.DurationBarColor = color;
}
}

protected DataTable getData(DateTime dtinicio, DateTime dtfim)
{
int codcolaborador = 0;
int codespecialidade = 0;
int codunidade = 0;
int codprocedimento = 0;

if (ddUnidade.SelectedValue != "")
codunidade = Convert.ToInt32(ddUnidade.SelectedValue);

if (ddMedico.SelectedValue != "TODOS")
codcolaborador = Convert.ToInt32(ddMedico.SelectedValue);

if (ddEspecialidade.SelectedValue != "")
codespecialidade = Convert.ToInt32(ddEspecialidade.SelectedValue);

if (ddAgendaPara.SelectedValue == "1")
codprocedimento = Convert.ToInt32(ddExame.SelectedValue);

string horainicio = "00:00";
string horafim = "23:59";

DataView DV = BusinessMed.LoadAgendaMedico(codunidade, codcolaborador, codespecialidade, txDtInicio.Date, codprocedimento, horainicio, horafim);
DV.RowFilter = " (DTAGENDAINICIO >= '" + dtinicio.ToString("yyyy-MM-dd") + " 00:00:00' AND DTAGENDAINICIO <= '" + dtfim.ToString("yyyy-MM-dd") + "') ";

DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name2", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("color", typeof(string));

for (int i = 0; i < DV.Count; i++)
{
if (ckExibeHorarioVago.Checked)
{
DataRow dr;
dr = dt.NewRow();
dr["start"] = Convert.ToDateTime(DV[i]["DTAGENDAINICIO"]);
dr["end"] = Convert.ToDateTime(DV[i]["DTAGENDAFIMPROCED"]);
dr["name2"] = DV[i]["CLIENTE"].ToString();
if (DV[i]["CLIENTE"].ToString() == "")
{
dr["id"] = 0;
dr["color"] = "lightgreen";
}
else
{
dr["id"] = Convert.ToInt32(DV[i]["CODCLIENTE"]);
int posicaoFinal = DV[i]["CLIENTE"].ToString().IndexOf(' ');
string primeironome = "";
if (posicaoFinal != -1)
primeironome = DV[i]["CLIENTE"].ToString().Substring(0, posicaoFinal);
dr["name2"] = primeironome + "<BR>" + DV[i]["NOMEPROCED"].ToString() + "<BR>" + DV[i]["NOME"].ToString();
dr["color"] = "red";
}
dt.Rows.Add(dr);
}
else
{
if (DV[i]["CLIENTE"].ToString() != "")
{
DataRow dr;
dr = dt.NewRow();
dr["start"] = Convert.ToDateTime(DV[i]["DTAGENDAINICIO"]);
dr["end"] = Convert.ToDateTime(DV[i]["DTAGENDAFIMPROCED"]);

int posicaoFinal = DV[i]["CLIENTE"].ToString().IndexOf(' ');
string primeironome = "";
if (posicaoFinal != -1)
primeironome = DV[i]["CLIENTE"].ToString().Substring(0, posicaoFinal);
dr["name2"] = primeironome + "<BR>" + DV[i]["NOMEPROCED"].ToString() + "<BR>" + DV[i]["NOME"].ToString();
dr["id"] = Convert.ToInt32(DV[i]["CODCLIENTE"]);
dr["color"] = "red";
dt.Rows.Add(dr);
}
}
}
return dt;
}

protected DataTable getDataDia(DateTime dtinicio, int CODCOLABORADOR)
{
int codcolaborador = 0;
int codespecialidade = 0;
int codunidade = 0;
int codprocedimento = 0;

if (ddUnidade.SelectedValue != "")
codunidade = Convert.ToInt32(ddUnidade.SelectedValue);

if (ddMedico.SelectedValue != "TODOS")
codcolaborador = Convert.ToInt32(ddMedico.SelectedValue);
else
codcolaborador = CODCOLABORADOR;

if (ddEspecialidade.SelectedValue != "")
codespecialidade = Convert.ToInt32(ddEspecialidade.SelectedValue);

if (ddAgendaPara.SelectedValue == "1")
codprocedimento = Convert.ToInt32(ddExame.SelectedValue);

string horainicio = "00:00";
string horafim = "23:59";

DataView DV = BusinessMed.LoadAgendaMedico(codunidade, codcolaborador, codespecialidade, txDtInicio.Date, codprocedimento, horainicio, horafim);
DV.RowFilter = " (DTAGENDAINICIO >= '" + dtinicio.ToString("yyyy-MM-dd") + " 00:00:00' AND DTAGENDAINICIO <= '" + dtinicio.ToString("yyyy-MM-dd") + " 23:59:59') ";

DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("color", typeof(string));

for (int i = 0; i < DV.Count; i++)
{
if (ckExibeHorarioVago.Checked)
{
DataRow dr;
dr = dt.NewRow();
dr["start"] = Convert.ToDateTime(DV[i]["DTAGENDAINICIO"]);
dr["end"] = Convert.ToDateTime(DV[i]["DTAGENDAFIMPROCED"]);
dr["name"] = DV[i]["CLIENTE"].ToString();
if (DV[i]["CLIENTE"].ToString() == "")
{
dr["id"] = 0;
dr["color"] = "lightgreen";
}
else
{
dr["id"] = Convert.ToInt32(DV[i]["CODCLIENTE"]);
int posicaoFinal = DV[i]["CLIENTE"].ToString().IndexOf(' ');
string primeironome = "";
if (posicaoFinal != -1)
primeironome = DV[i]["CLIENTE"].ToString().Substring(0, posicaoFinal);
dr["name"] = primeironome + "<BR>" + DV[i]["NOMEPROCED"].ToString() + "<BR>" + DV[i]["NOME"].ToString();
dr["color"] = "red";
}
dt.Rows.Add(dr);
}
else
{
if (DV[i]["CLIENTE"].ToString() != "")
{
DataRow dr;
dr = dt.NewRow();
dr["start"] = Convert.ToDateTime(DV[i]["DTAGENDAINICIO"]);
dr["end"] = Convert.ToDateTime(DV[i]["DTAGENDAFIMPROCED"]);

int posicaoFinal = DV[i]["CLIENTE"].ToString().IndexOf(' ');
string primeironome = "";
if (posicaoFinal != -1)
primeironome = DV[i]["CLIENTE"].ToString().Substring(0, posicaoFinal);
dr["name"] = primeironome + "<BR>" + DV[i]["NOMEPROCED"].ToString() + "<BR>" + DV[i]["NOME"].ToString();
dr["id"] = Convert.ToInt32(DV[i]["CODCLIENTE"]);
dr["color"] = "red";
dt.Rows.Add(dr);
}
}
}
return dt;
}

#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);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{

}
#endregion

protected void ddMedico_SelectedIndexChanged(object sender, EventArgs e)
{
// se habilitar TODOS, esse selectedIndex abaixo tem que ser 1 ao invés de 0.
DayPilotCalendar1.Visible = false;
btnFiltrar0.Visible = false;
btnFiltrar1.Visible = false;
if (ddMedico.SelectedIndex > 0) // Diferente de TODOS
{
ddEspecialidade.Enabled = true;
ddEspecialidade.DataSource = BusinessEsp.LoadEspColab(Convert.ToInt32(ddMedico.SelectedValue));
ddEspecialidade.DataTextField = "NOMEESPECIALIDADE";
ddEspecialidade.DataValueField = "CODESPECIALIDADE";
ddEspecialidade.DataBind();
FuncGerais.geraItemSelecione(ddEspecialidade, true);
if (ddEspecialidade.Items.Count == 2)
{
ddEspecialidade.SelectedIndex = 1;
}
}
else // TODOS
{
ddEspecialidade.Enabled = true;
ddEspecialidade.DataSource = BusinessEsp.LoadEspecialidade();
ddEspecialidade.DataTextField = "NOMEESPECIALIDADE";
ddEspecialidade.DataValueField = "CODESPECIALIDADE";
ddEspecialidade.DataBind();
FuncGerais.geraItemSelecione(ddEspecialidade, true);
if (ddEspecialidade.Items.Count == 2)
{
ddEspecialidade.SelectedIndex = 1;
}
}
}

protected void ddUnidade_SelectedIndexChanged(object sender, EventArgs e)
{

if (ddUnidade.SelectedIndex > 0)
{
DataView DVMedico = BusinessMed.LoadMedico(ViewState["login"].ToString());
if (DVMedico.Count > 0)
{
if (DVMedico[0]["BITOUTRAAGENDA"].ToString() == "1")
ddMedico.DataSource = BusinessMed.LoadMedico(Convert.ToInt32(ddUnidade.SelectedValue));
else
ddMedico.DataSource = BusinessMed.LoadMedico(Convert.ToInt32(DVMedico[0]["CODCOLABORADOR"]), true);
}
else
ddMedico.DataSource = BusinessMed.LoadMedico(Convert.ToInt32(ddUnidade.SelectedValue));

ddMedico.DataTextField = "NOME";
ddMedico.DataValueField = "CODCOLABORADOR";
ddMedico.DataBind();
FuncGerais.geraItemTodos(ddMedico, true);
if (ddMedico.Items.Count == 2)
{
ddMedico.SelectedIndex = 1;
ddMedico_SelectedIndexChanged(ddMedico, null);
}
else
{
ddEspecialidade.Enabled = true;
ddEspecialidade.DataSource = BusinessEsp.LoadEspecialidade();
ddEspecialidade.DataTextField = "NOMEESPECIALIDADE";
ddEspecialidade.DataValueField = "CODESPECIALIDADE";
ddEspecialidade.DataBind();
FuncGerais.geraItemSelecione(ddEspecialidade, true);
if (ddEspecialidade.Items.Count == 2)
{
ddEspecialidade.SelectedIndex = 1;
}
}
}
}

protected void btnFiltrar2_Click(object sender, EventArgs e)
{
if (rbTipo.SelectedValue == "0") // semana
{
DayPilotCalendar1.CellDuration = 15;
DayPilotCalendar1.BusinessBeginsHour = 7;
DayPilotCalendar1.BusinessEndsHour = 24;
DayPilotCalendar1.Visible = true;
btnFiltrar0.Visible = true;
btnFiltrar1.Visible = true;
if ((ddUnidade.SelectedIndex <= 0 || ddEspecialidade.SelectedIndex <= 0) && ddAgendaPara.SelectedValue == "0")
{
ScriptManager.RegisterClientScriptBlock(ddUnidade, typeof(DropDownList), "Acao", "alert('Unidade e especialidade devem ser informados.')", true);
}
else if ((ddUnidade.SelectedIndex <= 0 || ddExame.SelectedIndex <= 0) && ddAgendaPara.SelectedValue == "1")
{
ScriptManager.RegisterClientScriptBlock(ddUnidade, typeof(DropDownList), "Acao", "alert('Unidade e exame devem ser informados.')", true);
}
else
{
ViewState["DataAtual"] = txDtInicio.Date;
FiltraCalendario(Convert.ToDateTime(ViewState["DataAtual"]), DayOfWeek.Sunday);
}
}
else // diaria
{
DayPilotCalendar1.Visible = false;
DayPilotCalendar1.CellDuration = 15;
DayPilotCalendar1.BusinessBeginsHour = 7;
DayPilotCalendar1.BusinessEndsHour = 24;
btnFiltrar0.Visible = true;
btnFiltrar1.Visible = true;
if ((ddUnidade.SelectedIndex <= 0 || ddEspecialidade.SelectedIndex <= 0) && ddAgendaPara.SelectedValue == "0")
{
ScriptManager.RegisterClientScriptBlock(ddUnidade, typeof(DropDownList), "Acao", "alert('Unidade e especialidade devem ser informados.')", true);
}
else if ((ddUnidade.SelectedIndex <= 0 || ddExame.SelectedIndex <= 0) && ddAgendaPara.SelectedValue == "1")
{
ScriptManager.RegisterClientScriptBlock(ddUnidade, typeof(DropDownList), "Acao", "alert('Unidade e exame devem ser informados.')", true);
}
else
{
ViewState["DataAtual"] = txDtInicio.Date;
DataView dvMedico;
if (ddMedico.SelectedValue == "TODOS")
dvMedico = BusinessMed.LoadMedicoEspecialidade(Convert.ToInt32(ddEspecialidade.SelectedValue));
else
dvMedico = BusinessMed.LoadMedico(Convert.ToInt32(ddMedico.SelectedValue), true);
FiltraCalendarioDia(Convert.ToDateTime(ViewState["DataAtual"]), dvMedico);
}
}
}

public void FiltraCalendario(DateTime dataAtual, DayOfWeek domingo)
{
DayPilotCalendar1.StartDate = firstDayOfWeek(dataAtual, domingo);
DayPilotCalendar1.DataSource = getData(DayPilotCalendar1.StartDate, DayPilotCalendar1.StartDate.AddDays(7));
DayPilotCalendar1.DataBind();
DayPilotCalendar1.HeaderDateFormat = "ddd dd/MM/yyyy";
}

public void FiltraCalendarioDia(DateTime dataAtual, DataView DVMedico)
{
Table tb = new Table();
tb.Width = Unit.Percentage(100);
TableRow tr = new TableRow();
tr.Width = Unit.Percentage(100);

double width;
width = 100 / DVMedico.Count;
for (int i = 0; i < DVMedico.Count; i++)
{
TableCell tc = new TableCell();
tc.ID = "tc" + DVMedico[i]["CODCOLABORADOR"].ToString();

DayPilot.Web.Ui.DayPilotCalendar d3 = new DayPilot.Web.Ui.DayPilotCalendar();
//d3.EventClickHandling = DayPilotCalendar1.EventClickHandling;
//d3.EventClickJavaScript = DayPilotCalendar1.EventClickJavaScript;
//d3.Events += new DayPilot.Web.Ui.Events.EventClickEventHandler(d3_EventClick);
//d3.EventClick += new DayPilotCalendar1_EventClick(d3, null);
//d3.EventClickHandling = DayPilot.Web.Ui.Enums.EventClickHandlingEnum.CallBack;
//d3.EventClick += new DayPilot.Web.Ui.Events.EventClickEventHandler(d3_EventClick);
d3.ID = "d3" + DVMedico[i]["CODCOLABORADOR"].ToString();
d3.DataStartField = "Start";
d3.DataTextField = "name";
d3.DataValueField = "id";
d3.DataEndField = "End";
d3.StartDate = dataAtual;
d3.CellDuration = 15;
d3.BusinessBeginsHour = 7;
d3.BusinessEndsHour = 24;
d3.DataSource = getDataDia(d3.StartDate, Convert.ToInt32(DVMedico[i]["CODCOLABORADOR"]));
d3.DataBind();
d3.HeaderDateFormat = "ddd dd/MM/yyyy";

d3.Width = Unit.Percentage(100);
d3.BusinessBeginsHour = 7;
d3.BusinessEndsHour = 24;
d3.TimeFormat = DayPilot.Web.Ui.Enums.TimeFormat.Clock24Hours;
Label lb = new Label();
lb.ID = "lb" + DVMedico[i]["CODCOLABORADOR"].ToString();
lb.Text = DVMedico[i]["NOME"].ToString();
tc.Controls.Add(lb);
tc.Controls.Add(d3);
tr.Cells.Add(tc);
}
tb.Rows.Add(tr);
TCDIA2.Controls.Add(tb);
TCDIA2.Width = "100%";
/*
DayPilotCalendar2.StartDate = dataAtual;
DayPilotCalendar2.DataSource = getDataDia(DayPilotCalendar2.StartDate);
DayPilotCalendar2.DataBind();
DayPilotCalendar2.HeaderDateFormat = "ddd dd/MM/yyyy";
DayPilotCalendar2.Width = Unit.Percentage(100);
*/
}

protected void ddAgendaPara_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddAgendaPara.SelectedValue == "0")
{
TRMEDICO.Visible = true;
TREXAME.Visible = false;
}
else
{
TRMEDICO.Visible = false;
TREXAME.Visible = true;
}
}
protected void btnFiltrar0_Click(object sender, EventArgs e)
{
ViewState["DataAtual"] = Convert.ToDateTime(ViewState["DataAtual"]).AddDays(-7);
FiltraCalendario(Convert.ToDateTime(ViewState["DataAtual"]), DayOfWeek.Sunday);
}
protected void btnFiltrar1_Click(object sender, EventArgs e)
{
ViewState["DataAtual"] = Convert.ToDateTime(ViewState["DataAtual"]).AddDays(7);
FiltraCalendario(Convert.ToDateTime(ViewState["DataAtual"]), DayOfWeek.Sunday);
}
protected void DayPilotCalendar1_EventClick(object sender, DayPilot.Web.Ui.Events.EventClickEventArgs e)
{
if (e.Value != "0")
Response.Redirect("cadastro_clientes.aspx?CodCliente=" + e.Value);
}

protected void d3_EventClick(object sender, DayPilot.Web.Ui.Events.EventClickEventArgs e)
{
if (e.Value != "0")
Response.Redirect("cadastro_clientes.aspx?CodCliente=" + e.Value);
}

protected void rbTipo_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbTipo.SelectedValue == "0")
{
TRSEMANA1.Visible = true;
TRSEMANA2.Visible = true;
TRDIA1.Visible = false;
TRDIA2.Visible = false;
}
else
{
TRSEMANA1.Visible = false;
TRSEMANA2.Visible = false;
TRDIA1.Visible = true;
TRDIA2.Visible = true;
}
}
}

Comment posted by Dan Letecky [DayPilot]
10 years ago.

You have to create and initialize the d3 object in Page_Load or otherwise ensure that the object is created during CallBack so that can be found using its ID.

DayPilot.Web.Ui.DayPilotCalendar d3 = new DayPilot.Web.Ui.DayPilotCalendar();
d3.ID = "d3" + DVMedico[i]["CODCOLABORADOR"].ToString();
...

You create this object conditionally in FiltraCalendarioDia(). If you want to handle its events on the server side you need to make sure it exists. Otherwise that ASP.NET CallBack/PostBack event handling mechanism doesn't know what to do with the event.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.