Using the calendar date picker does not trigger the fields onchanged event


#1

I have a date field: LEAVE_END_DT
When the date text is changed I want to set the value in another text field: LEAVE_TOTAL_DAYS

If I change the text in LEAVE_END_DT everything works fine. But if I use the calendar date picker then onchanged or ontextchanged events are not triggered.


#2

Hi David,

You need to add an event on “date changed” event in the calendar. You can use the following code as an example.

protected void Page_Load(object sender, EventArgs e)
{
	base.Page_Load(sender, e);
	        
	if(!IsPostBack)
	{
		LEAVE_END_DT_CAL.AutoPostBack = true;
		LEAVE_END_DT_CAL.DateChanged += LEAVE_END_DT_CAL_DateChanged;
	}
}

protected void LEAVE_END_DT_CAL_DateChanged(object sender, EventArgs e)
{
	// Your code here
}

Regards,
Quentin


#3

Thanks Quentin,

I’ve put that code on the .net tab, and instead of // Your code here I have:
LEAVE_TOTAL_DAYS.Text = “test”;

But when I use the calendar picker for LEAVE_END_DT it still doesn’t set LEAVE_TOTAL_DAYS to test.

Not sure what I am doing wrong?


#4

Hi David,

The event handler should be outside the !IsPostBack clause so that it executes when the postback occurs . Try this and let me know if it works:

protected void Page_Load(object sender, EventArgs e)
{
	base.Page_Load(sender, e);
	        
	if(!IsPostBack)
	{
		LEAVE_END_DT_CAL.AutoPostBack = true;
	}

        LEAVE_END_DT_CAL.DateChanged += LEAVE_END_DT_CAL_DateChanged;
}

protected void LEAVE_END_DT_CAL_DateChanged(object sender, EventArgs e)
{
	// Your code here
}