diff --git a/js/aspnet.js b/js/aspnet.js index a2d120d2e810..8c31d6168cfd 100644 --- a/js/aspnet.js +++ b/js/aspnet.js @@ -27,6 +27,7 @@ } })(function($, setTemplateEngine, templateRendered, Guid, validationEngine, iteratorUtils, extractTemplateMarkup, encodeHtml) { var templateCompiler = createTemplateCompiler(); + var pendingCreateComponentRoutines = [ ]; function createTemplateCompiler() { var OPEN_TAG = "<%", @@ -123,19 +124,21 @@ } function createComponent(name, options, id, validatorOptions) { - var render = function(_, container) { - templateRendered.remove(render); - - var selector = "#" + id.replace(/[^\w-]/g, "\\$&"), - $component = $(selector, container)[name](options); + var selector = "#" + id.replace(/[^\w-]/g, "\\$&"); + pendingCreateComponentRoutines.push(function() { + var $component = $(selector)[name](options); if($.isPlainObject(validatorOptions)) { $component.dxValidator(validatorOptions); } - }; - - templateRendered.add(render); + }); } + templateRendered.add(function() { + var snapshot = pendingCreateComponentRoutines.slice(); + pendingCreateComponentRoutines = [ ]; + snapshot.forEach(function(func) { func(); }); + }); + return { createComponent: createComponent, diff --git a/testing/tests/DevExpress.aspnet/aspnet.tests.js b/testing/tests/DevExpress.aspnet/aspnet.tests.js index afcc9f2ac098..53a6934f6d58 100644 --- a/testing/tests/DevExpress.aspnet/aspnet.tests.js +++ b/testing/tests/DevExpress.aspnet/aspnet.tests.js @@ -415,7 +415,7 @@ $("#qunit-fixture").html( - '
' + + '
' + '
' + '' ); - $("#popop1").dxPopup({ + $("#popup1").dxPopup({ contentTemplate: $("#popup1_contentTemplate"), visible: true }); @@ -452,4 +452,34 @@ } }); + QUnit.test("T810336", function(assert) { + aspnet.setTemplateEngine(); + + window.__createButton = function(buttonID) { + DevExpress.aspnet.createComponent("dxButton", { text: buttonID }, buttonID); + }; + + try { + $("#qunit-fixture").html( + '
' + + '' + ); + + $("#popup1").dxPopup({ + contentTemplate: $("#popup1_contentTemplate"), + visible: true + }); + + assert.ok($("#b1").dxButton("instance")); + assert.ok($("#b2").dxButton("instance")); + + } finally { + setTemplateEngine("default"); + delete window.__createButton; + } + }); + }));