on 02-14-2013 07:30 PM - edited on 07-25-2024 11:56 AM by Nils
This page covers how you can create custom widgets in Lansweeper On-premises.
Creating a custom data widget in Lansweeper On-premises is a straightforward process, especially when displaying data like SQL query results that don't require user input.
In this article, we'll walk you through building a basic widget. We'll start from basic data retrieval, and then explore enhancing your widget with images, links, and additional functionality such as auto-refresh.
Whether you're showcasing asset groups or providing quick links to configuration pages, these steps will help you craft an informative and visually appealing widget for your Lansweeper setup.
The simplest widgets to create are those that display data, such as the results of a SQL query, without needing user input.
In this first example, we'll demonstrate how to create a basic widget and add it to Lansweeper On-prem.
/WidgetsCustom/
folder.<%@ Page Language="C#" AutoEventWireup="true" Inherits="LS.BaseControl" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="LS.Enums" %>
<%@ Import Namespace="LS" %>
<% Response.CacheControl = "no-cache";%>
<% Response.AddHeader("Pragma", "no-cache"); %>
<% Response.Expires = -1; %>
<% LS.User.Current().CheckUserWebsiteAccess(); %>
var dsAssets = DB.ExecuteDataset("SELECT tblAssetGroups.AssetGroup, tblAssetGroups.AssetGroupid, COUNT(tblAssetGroupLink.AssetID) AS Count FROM tblAssetGroups INNER JOIN tblAssetGroupLink ON tblAssetGroups.AssetGroupID = tblAssetGroupLink.AssetGroupID GROUP BY tblAssetGroups.AssetGroup, tblAssetGroups.AssetGroupid");
if (dsAssets.Rows.Count != 0)
{%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<% foreach (DataRow myrow in dsAssets.Rows)
{%>
<tr>
<td align="left" valign="top">
<%:myrow["AssetGroup"]%>
</td>
<td align="right" valign="top">
<%:myrow["Count"]%>
</td>
</tr>
<% }%>
</table>
<%}%>
In addition to displaying data, you can enhance your widget by including images or links to other pages. This not only makes the widget more visually appealing, but also adds extra functionality. You can use images from the existing /images/
folder or add your own images to the /WidgetsCustom/images
folder.
<%=ResolveUrl("~/")%>
.<td width="10" align="left" valign="top">
<img src="<%=ResolveUrl("~/")%>images/tag_green.png" width="16" height="16" hspace="2" vspace="2" />
</td>
<%if (LS.User.Current().IsInRole(Permission.EditConfiguration))
{%><div style="float:right">
<a href="<%=ResolveUrl("~/")%>configuration/AssetGroups/" class="sml">config</a>
</div><% } %>
<td align="left" >
<a href="<%=ResolveUrl("~/")%>report.aspx?det=web50getassetgroups&@assetgroupid=<%:myrow["AssetGroupid"]%>&title=Assets in group <%= HttpUtility.UrlEncode(myrow["AssetGroup"].ToString()) %>"><%: myrow["AssetGroup"] %></a>
</td>
<script type="text/javascript">
$('#WTitle<%=TabControlID %>', window.top.document).text("Just a simple test widget");
</script>
For auto-refresh to function properly, ensure that your control inherits from LS.BaseControl
in the heading:<%=AutoRefresh(10) %>
Putting all previous steps together gives us the following:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="LS.BaseControl" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="LS.Enums" %>
<%@ Import Namespace="LS" %>
<% Response.CacheControl = "no-cache";%>
<% Response.AddHeader("Pragma", "no-cache"); %>
<% Response.Expires = -1; %>
<% LS.User.Current().CheckUserWebsiteAccess(); %>
<%var dsAssets = DB.ExecuteDataset("SELECT tblAssetGroups.AssetGroup, tblAssetGroups.AssetGroupid, COUNT(tblAssetGroupLink.AssetID) AS Count FROM tblAssetGroups INNER JOIN tblAssetGroupLink ON tblAssetGroups.AssetGroupID = tblAssetGroupLink.AssetGroupID GROUP BY tblAssetGroups.AssetGroup, tblAssetGroups.AssetGroupid");
if (dsAssets.Rows.Count != 0)
{%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<% foreach (DataRow myrow in dsAssets.Rows)
{%>
<tr>
<td width="10" align="left" valign="top">
<img src="<%=ResolveUrl("~/")%>images/tag_green.png" width="16" height="16" hspace="2" vspace="2" />
</td>
<td align="left" ><a href="<%=ResolveUrl("~/")%>report.aspx?det=web50getassetgroups&@assetgroupid=<%:myrow["AssetGroupid"]%>&title=Assets in group <%= HttpUtility.UrlEncode(myrow["AssetGroup"].ToString()) %>"><%: myrow["AssetGroup"] %></a></td>
<td align="right" valign="top">
<%:myrow["Count"]%>
Was this post helpful? Select Yes or No below!
Did you have a similar issue and a different solution? Or did you not find the information you needed? Create a post in our Community Forum for your fellow IT Heroes!
More questions? Browse our Quick Tech Solutions.
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try NowExperience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now