Khristian Liahut Khristian Liahut - 1 year ago 276
Javascript Question

DataTables warning (table id = 'IDTableName'): Cannot reinitialise DataTable

I'm using Jquery Datatable in ASP.NET, and UpdatePanel (scriptManager) .
I have the next below error:

DataTables warning (table id = 'tbVerificationApplicant'): Cannot
reinitialise DataTable.

To retrieve the Datatables object for this table, pass no argument or
see the docs for bRetrieve and bDestroy

This is the Jquery file to create the table:

function DatatablesExec() {
'bProcessing': true,
'bServerSide': true,
"sPaginationType": "full_numbers",
'sAjaxSource': 'listVerificationData.ashx?ddlStatusValue=' + $("#ddlStatusClient option:selected").text(),
"fnDrawCallback": function () {
$('#tbVerificationApplicant tbody tr').click(function () {
var hRef = $("td:eq(0)", this).text();
document.location.href = 'frm_VerifyIdentity.aspx?ID=' + hRef;

$(document).ready(function () {
/* Initialise the DataTable */



But, to avoid that the table desapear after I changed the dropdownlist, I added the next below code in the code behind in the web form.

protected void Page_Prerender(object sender, EventArgs e)
ScriptManager.RegisterStartupScript(this, this.GetType(), "_function_dummyname", "<script type='text/javascript'>DatatablesExec();</script>", false);

It's working well, but at the begining appear a pop up with this error.

Thi is part of the web form:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:AsyncPostBackTrigger ControlID="ddlStatusClient" EventName="SelectedIndexChanged" />
<table id="tbVerificationApplicant" class="display">

Answer Source

When your page loads ,your function DatatablesExec() is executed twice: once in code-behind Page_Prerender and once in $(document).ready function.

The error means you are trying to make a table a Datatable, when it infact is already a Datatable.

You will have to rethink your design here.

Why is it neccessary to RegisterStartupScript in PreRender?

Try removing either one of the two DatatablesExec() and your problem should dissapear!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download