We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Synfusion controls within content rendered within a Synfusion Tab control

Hi - I'm using the tab control with content that gets rendered from CSHTML partial views. All works fine, except that for any content that contains other SyncFusion controls the script block created by @Html.EJS().ScriptManager() is causing problems. If I render it within the partial view it causes an error (Invalid Token) - if I leave the @Html.EJS().ScriptManager() off and rely on the one in _Layout it won't realise it needs to render code for those controls within the partial view.
I've tried manipulating the rendered partial content using Regex to extract the script block and add it later - but I can't get it to consistently run at the right time.
What is your recommendation w.r.t. rendering content within a Tab control that contains other Syncfusion controls?

1 Reply

PO Prince Oliver Syncfusion Team January 2, 2019 10:18 AM UTC

Hi Charles, 
 
Thank you for using Syncfusion products. 
 
Query1:” What is your recommendation w.r.t. rendering content within a Tab control that contains other Syncfusion controls?” 
 
The recommended approach to load content in Tab is to use AJAX call that loads the content in the Tab on demand in the Created and Selected event of Tab. Kindly refer to the following code snippet.   
  
  
@Html.EJS().Tab("MainTab").Created("tabCreated").Selected("tabSelected").Render()  
  
<script>  
    var loaded = false;  
    function tabCreated(e) { // created event to create the Tab items and data for first tab   
        var tabObj = document.getElementById("MainTab").ej2_instances[0];  
        var ajax = new ej.base.Ajax('@Url.Action("PartialView1""Home")''GET'true);  
        ajax.send().then();  
        ajax.onSuccess = function (data) {  
            tabObj.addTab([{ header: { 'text''Grid1' }, "content""<div id='GridOrder1'></div>" }],0);  
            tabObj.addTab([{ header: { 'text''Grid2' }, "content""<div id='GridOrder2'></div>" }],1);  
            $("#GridOrder1").html(data);  
        }   
    }  
    function tabSelected(e) { // selected event to load data dynamically based on the selection of the tab item   
        if(e.selectedIndex != 0 && !loaded){  
            var tabObj = document.getElementById("MainTab").ej2_instances[0];  
            var ajax = new ej.base.Ajax('@Url.Action("PartialView2""Home")''GET'true);  
            ajax.send().then();  
            ajax.onSuccess = function (data) {                  
                $("#GridOrder2").html(data);   
                loaded = true;  
            }  
        }   
    }  
</script>  
  
In our example, we have created both the Header and content as dynamic. if you don’t want to set them as dynamic, then you can directly set the items in the same way we given in the example. 
 
We have attached the sample for your reference, please find the sample at the following link: http://www.syncfusion.com/downloads/support/directtrac/222473/ze/WebApplication2-753147216   
   
We have also explained the diverse ways to load Tab content in the below help pages:  
  
  
2.      From the items within same page or new Items:  https://ej2.syncfusion.com/documentation/tab/how-to/load-tab-items-dynamically/   
  
  
Kindly check the above help links and get back to us if you face any difficulties in achieving your requirement. 
 
Regards, 
Prince  


Loader.
Live Chat Icon For mobile
Up arrow icon