# Persist Selected Tab in the TabStrip

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Grid for Progress® Telerik® UI for ASP.NET MVC</td>
 </tr>
</table>

## Description

How can I persist the selected tab in the TabStrip when the user refreshes the page or navigates to another page?

## Solution

1. Handle the [`Select`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/tabstripeventbuilder#selectsystemfunc) event of the TabStrip and get the name of the selected tab. Send it through an `AJAX` request to the server and store it.

   ```Razor View
   	@{
   		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>
   ```

   ```C# Controller
   	public class HomeController : Controller
   	{
   		public static string SelectedTabInfo;

   		public ActionResult Index()
   		{
   			if (SelectedTabInfo == null)
   			{
   				ViewData["tabinfo"] = "";
   				SelectedTabInfo = "";
   			}
   			else
   			{
   				ViewData["tabinfo"] = SelectedTabInfo;
   			}
   			return View();
   		}

   		public ActionResult SaveTabName(string name)
   		{
   			ViewData["tabinfo"] = name;
   			SelectedTabInfo = name;
   			return new JsonResult(true);
   		}
   	}
   ```

2. When the document is ready, get the name of the selected tab through the `ViewData["tabinfo"]` and activate the respective tab.

   ```Razor View
   	<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>
   ```

## More ASP.NET MVC TabStrip Resources

* [ASP.NET MVC TabStrip Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/navigation/tabstrip/overview)

* [ASP.NET MVC TabStrip Demos](https://demos.telerik.com/aspnet-mvc/tabstrip)

* [ASP.NET MVC TabStrip Product Page](https://www.telerik.com/aspnet-mvc/tabstrip)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the TabStrip for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/tabstrip)
* [Server-Side API Reference of the TabStrip for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/tabstrip)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
