Karine Bosch’s Blog

On SharePoint

LinkSection.ascx and LinksTable.ascx Control


LinkSection.ascx

When developing application pages you can use this control to display links. The control LinkSection.ascx is located in the 12\CONTROLTEMPLATES folder.

linksection

You can click on one of the hyperlinks to get redirected.

To include a a LinkSection control in its most simple way on an application page you have to use the following syntax:

<wssuc:LinkSection ID="LinkSection1" runat="server" Title="Links"
       Description="This section demonstrates the LinkSection.">
       <Template_Links>
            <asp:HyperLink ID="ptLink" runat="server" NavigateUrl="http://www.u2u.info/blogs/patrick" Text="Profkes blog" />
            <asp:HyperLink ID="acLink" runat="server" NavigateUrl="http://www.andrewconnell.com/blog/" Text="ACs blog" />
            <asp:HyperLink ID="blogLink" runat="server" NavigateUrl="https://karinebosch.wordpress.com" Text="my blog" />
       </Template_Links>
</wssuc:LinkSection>

Add also a directive at the top of the page:

<%@ Register TagPrefix="wssuc" TagName="LinkSection" Src="/_controltemplates/LinkSection.ascx" %>

It is evident that you can complicate the content of the <Template_Links> element at your desire. You can work with data sources and Repeater or GridView controls.

As with the InputFormSection control, you can add a template for the title and/or description if you want it more richer than a single string.

<wssuc:LinkSection ID="LinkSection1" runat="server">
     <template_title>
          <spuc:EncodedLiteral ID="EncodedLiteral1" runat="server" text="My Links" EncodeMethod='HtmlEncode'/>
     </template_title>
     <template_description>
          <spuc:EncodedLiteral ID="EncodedLiteral2" runat="server" text="My rich description..." EncodeMethod='HtmlEncode'/>
     </template_description>
     <template_links>
          <asp:HyperLink ID="ptLink" runat="server" NavigateUrl="http://www.u2u.info/blogs/patrick" Text="Profkes blog" />
          <asp:HyperLink ID="acLink" runat="server" NavigateUrl="http://www.andrewconnell.com/blog/" Text="ACs blog" />
          <asp:HyperLink ID="blogLink" runat="server" NavigateUrl="https://karinebosch.wordpress.com" Text="my blog" />
     </template_links>
</wssuc:LinkSection>

If you want to add extra content or information at the bottom of the section, you can use the <Template_OtherControls> element in which you can place the required controls.

linksection-extra

<wssuc:LinkSection ID="LinkSection1" runat="server">
     <template_title>
          <spuc:EncodedLiteral ID="EncodedLiteral1" runat="server" text="My Links" EncodeMethod='HtmlEncode'/>
     </template_title>
     <template_description>
          <spuc:EncodedLiteral ID="EncodedLiteral2" runat="server" text="My rich description..." EncodeMethod='HtmlEncode'/>
     </template_description>
     <template_links>
          <asp:HyperLink ID="acLink" runat="server" NavigateUrl="http://www.andrewconnell.com/blog/"
               Text="ACs blog" Tooltip="navigate to the blog of Andrew Connell" />
          <asp:HyperLink ID="ptLink" runat="server" NavigateUrl="http://www.u2u.info/blogs/patrick"
               Text="Profkes blog" ToolTip="navigate to the blog of Patrick Tisseghem" />
          <asp:HyperLink ID="blogLink" runat="server" NavigateUrl="https://karinebosch.wordpress.com"
               Text="my blog" Tooltip="navigate to the blog of Karine Bosch" />
      </template_links>
      <template_OtherControls>
           You can specify additional information in this OtherControls template.
           F.e. hover over the hyperlink to see a tooltip.                                   
      </template_OtherControls>
</wssuc:LinkSection>

 

If you want to add a LinkSection control to a web part you have to define it from scratch in your web part code. You can find an excellent example here.

The Links property is a collection of controls containing the links defined in the <template_Links> element.

 

LinksTable.ascx

If you only want the links to be displayed in a SharePoint-like way, without a section header and description, you can use the LinksTable.ascx user control. You can define a <template_Links> element as in the LinkSection.ascx control:

    <wssuc:LinksTable ID="BlogLinksTable" runat="server">
         <template_links>
             <asp:HyperLink ID="acLink2" runat="server" NavigateUrl="http://www.andrewconnell.com/blog/" 
                            Text="ACs blog" Tooltip="navigate to the blog of Andrew Connell" />
             <asp:HyperLink ID="ptLink2" runat="server" NavigateUrl="http://www.u2u.info/blogs/patrick" 
                            Text="Profkes blog" ToolTip="navigate to the blog of Patrick Tisseghem" />
             <asp:HyperLink ID="blogLink2" runat="server" NavigateUrl="https://karinebosch.wordpress.com" 
                            Text="my blog" Tooltip="navigate to the blog of Karine Bosch" />
         </template_links>
    </wssuc:LinksTable>

If you want to  use the LinksTable control in a web part, you have to define it from scratch. You can find a code sample here.

The Links property is a collection of controls containing the links defined in the <template_Links> element.

Advertisements

3 Comments »

  1. tks for the effort you put in here I appreciate it!

    Comment by MichaellaS | July 21, 2009 | Reply

  2. Can I display user specific link?

    For example I have added 5 link as site owner and I want that other user who are not part of owner group can only see first 3 links.

    How can I implement this?

    Thanks

    Sonaly

    Comment by Sonaly | March 1, 2010 | Reply

  3. Hi sonaly,
    I’m afraid this is not possible out of the box. You could create a custom web part that renders this LinkSection control programmatically and that renders URLs based on the credentials of the logged on user.
    Karine

    Comment by Karine Bosch | March 1, 2010 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: