Search code examples
javascriptasp.netasp.net-ajaxajaxcontroltoolkit

Is it possible to remove a behavior from an element that was added using $create?


I am using the following code to create calendar controls on textboxes that have been dynamically created using cloneNode. The problem is that in IE it seems to add the behavior twice to the textbox causing it not to work. Is there a way that I can remove this behavior before it is added in ie only to prevent it from being added again? This works perfectly in firefox. Thanks!

var rawDateControlID = ctrlPrefix + 'txtStartDate' + tblPatientMedicationsRowCount;
var $tstCalendar = $("#" + rawDateControlID);
$create(AjaxControlToolkit.CalendarBehavior, { "id": $tstCalendar.attr("id") + "cld" }, null, null, $get($tstCalendar.attr("id")));

Solution

  • This seems to help in certain cases:

    var $tstCalendar = $('#' + txtStartDateID);    
    if ($find($tstCalendar.attr("id") + "cld"))
    {
       $find($tstCalendar.attr("id") + "cld").dispose();
    }
    $create(AjaxControlToolkit.CalendarBehavior, { "id": $tstCalendar.attr("id") + "cld" }, null, null, $get($tstCalendar.attr("id")));
    

    Just checking if the behaviour exists and if it does get rid of it before creating the new one.