New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Persist Selected Tab in the TabStrip
Environment
Product | Grid for Progress® Telerik® UI for ASP.NET Core |
Description
How can I persist the selected tab in the TabStrip when the user refreshes the page or navigates to another page?
Solution
-
Handle the
Select
event of the TabStrip and get the name of the selected tab. Send it through anAJAX
request to the server and store it.Razor@{ var selectedTab = ViewData["tabinfo"]; } @(Html.Kendo().TabStrip() .Name("tabstrip") .Events(ev => ev.Select("onSelect")) // Other configuration ) <script> function onSelect(e) { if (e.item) { $.ajax({ type: "POST", url: "@Url.Action("SaveTabName","Home")", data: { name: e.item.innerText }, success: function(result) { if(result) { console.log("Successfully saved tab!"); } }, error: function(err) { console.log("Tab is not saved."); } }); } } </script>
-
When the document is ready, get the name of the selected tab through the
ViewData["tabinfo"]
and activate the respective tab.Razor<script> $(document).ready(function () { var savedTab = '@Html.Raw(selectedTab)'; if(savedTab != "") { var tabStrip = $("#tabstrip").data("kendoTabStrip"); var tabEelement = $("li:contains('" + savedTab + "')"); tabStrip.activateTab(tabEelement); // Activate the latest selected tab. } }); </script>