Getting Started with ASP.NET Core Tooltip Control

23 Jul 20265 minutes to read

This section briefly explains how to include the ASP.NET Core Tooltip control in an ASP.NET Core application using Visual Studio.

Create ASP.NET Core web application with Razor pages

Create an ASP.NET Core Web App using Visual Studio via Microsoft Templates or the ASP.NET Core Extension. For detailed instructions, refer to the ASP.NET Core Web App Getting Started documentation.

Install ASP.NET Core package in the application

To add ASP.NET Core Tooltip control in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search for and install the Syncfusion.AspNetCore.Popups and Syncfusion.AspNetCore.Themes packages. All Syncfusion ASP.NET Core packages are available in nuget.org. See the NuGet packages topic for details.

Alternatively, you can install the same package using the Package Manager Console with the following command.

Install-Package Syncfusion.AspNetCore.Popups -Version 34.1.29
Install-Package Syncfusion.AspNetCore.Themes -Version 34.1.29

Add the ASP.NET Core Tag Helper

After the packages are installed, open the ~/Pages/_ViewImports.cshtml file and import the Syncfusion.AspNetCore.Base and Syncfusion.AspNetCore.Popups Tag Helpers.

@addTagHelper *, Syncfusion.AspNetCore.Base
@addTagHelper *, Syncfusion.AspNetCore.Popups

Add stylesheet and script resources

The theme stylesheet and script can be referenced from NuGet through Static Web Assets. Include the stylesheet and script references inside the <head> of ~/Pages/Shared/_Layout.cshtml file.

<head>
    ...
    <link rel="stylesheet" href="_content/Syncfusion.AspNetCore.Themes/styles/fluent2.css" />
    <!-- Syncfusion ASP.NET Core controls scripts -->
    <script src="_content/Syncfusion.AspNetCore.Popups/scripts/sf-tooltip.min.js"></script>
</head>

Register the Script Manager

Open the ~/Pages/Shared/_Layout.cshtml file and register the script manager <ejs-scripts> at the end of the <body> element as follows.

<body>
    ...
    <!-- Syncfusion ASP.NET Core Script Manager -->
    <ejs-scripts></ejs-scripts>
</body>

Add ASP.NET Core Tooltip control

Add the ASP.NET Core Tooltip control in ~/Pages/Index.cshtml page.

<ejs-tooltip id="Tooltip" content="Lets go green & Save Earth !!!" position="TopCenter">
    <e-content-template>
        <span id='target'>Show Tooltip</span>
    </e-content-template>
</ejs-tooltip>

<style>
    #Tooltip {
        position: absolute;
        left: calc( 50% - 60px);
        top: 38%;
    }

</style>

NOTE

In the above sample code, #target is the id of the element in a page to which the Tooltip is initialized.

Run the application

Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. The ASP.NET Core Tooltip will render in your default web browser.

ASP.NET Core Tooltip Control

Initialize Tooltip within a container

You can create Tooltips on multiple targets within a container. To do so, you have to define specific target elements to the target property so that the Tooltip is initialized only on matched targets within a container. In this case, the Tooltip content is assigned from the title attribute of the target element.

Refer to the following code example to create a Tooltip on multiple targets within a container.

<ejs-tooltip id="details" position="RightCenter" target=".e-info">
	<e-content-template>
		<form id="details" role="form">
			<table>
				<tr>
					<td class="info"> User Name:</td>
					<td> <input type="text" class="e-info" name="firstname" title="Please enter your name"> </td>
				</tr>
				<tr>
					<td class="info"> Email Address:</td>
					<td> <input type="text" class="e-info" name="email" title="Enter a valid email address"></td>
				</tr>
				<tr>
					<td class="info"> Password:</td>
					<td> <input type="password" class="e-info" name="password" title="Be at least 8 characters length"></td>
				</tr>
				<tr>
					<td class="info"> Confirm Password:</td>
					<td> <input type="password" class="e-info" name="Cpwd" title="Re-enter your password"></td>
				</tr>
			</table>
			<input id="sample" type="submit" value="Submit">
			<input id="clear" type="reset" value="Reset">
		</form>
	</e-content-template>
</ejs-tooltip>

<style>
    #container {
        visibility: hidden;
    }

    #loader {
        color: #008cff;
        height: 40px;
        left: 45%;
        position: absolute;
        top: 45%;
        width: 30%;
    }

    #details table th, #details table td {
        padding: 15px;
        text-align: left;
    }

    #details .info {
        font-weight: bold;
    }
 
</style>

ASP.NET Core Tooltip with Accessibility

NOTE

In the above sample, #details refers to the container’s id, and the target .e-info refers to the target elements available within that container.

NOTE

View Sample in GitHub.

See also