Rendering html elements in SharePoint Webparts without explicit tags in ASCX file

Web Parts are part of the ASP.NET technology and are used extensively in Microsoft SharePoint installations. They are used to display or manipulate content on a SharePoint site by the end user. The changes made can be made visible for all or only for certain users. In addition, settings can be saved and assigned permanently to the user who made them. This allows users to tailor a web page to their own needs without the intervention of the administrator. This feature is called personalization.

For example, Web Parts are used to display SharePoint libraries or lists. For example, if a document library is created in a SharePoint site, it can be displayed multiple times on a SharePoint page by multiple Web Parts, for example, once by date of the last change and hierarchically by the folder structure of the document library. Also the selection of the displayed elements and attributes can be varied between the different Web Parts.

Like most SharePoint elements, Web Parts can be assigned and with separate display and editing rights. These are independent of the rights of the library or list displayed by the Web Part.

While building a Webpart solution in Visual Studio one other way of initializing and loading .js and .css files (also including glyphicons, images etc) while creating a SharePoint WebPart project is to add them in as a SPModule and including them as a Generic html controls or also as the namespace for this class goes as HtmlGenericControl

I will describe the following aspects which can be involved using HtmlGenericControl below :

  1. Meta Tags
  2. Script links
  3. Html tags (if necessary)

 

Meta Tags

Metadata is primarily intended to improve the searchability of the World Wide Web or a single website in SharePoint. In addition, specific instructions for controlling the search engines of search engines can be recorded using metadata. During the early days metadata was used as a secret weapon to be listed as far above as possible in a search engine.

In SharePoint Meta tags are used for optimal retrieval of information for your SharePoint site

Here below is a code which can be easily integrated into webpart ASCX CS file like this with the below code which includes the HtmlGenericControls.

The custom CSS and JS files are included as a SPModule and are referenced using a relative url

Script links

JS Link was introduced together with SharePoint 2013. It allows you to change the rendering of SharePoint controls on the client side without having to enter the master page or the controls directly. This is a huge advantage over previous versions of SharePoint, which had to be effortlessly adjusted with the help of content editor Web Parts or JavaScript files in the masterpage.

 

HTML Tags

Certain Html tags can be included along with giving them a certain ID or Class as below

 

Conclusion : One can implement html tags by directly introducing them in the ASCX file, which has many custom definition of the required layout, but sometimes the rendering of html elements can interfere with the functionality of the webpart. This method is just another way to introduce html elements into the webpart without editing the ASCX file.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑