HyperLink Field Control

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned

Overview

The HyperLink Field Control is a Field Control that handles HyperLink Fields and provides an interface to display/modify hyperlink text data.

ShortText Field Control in edit mode
ShortText Field Control in edit mode

Details

With HyperLink field control textual data store the URL, link text, link title and target data.

Supported Field types

Properties

For a complete list of common Field Control properties see common Field Control properties.

Templates

The HyperLink Field Control is a simple Field Control that renders TextBoxes. In Browse that display default values.

Browse view template

<%@  Language="C#" EnableViewState="false" %>
<%@ Import Namespace="SNControls=SenseNet.Portal.UI.Controls" %>
<%@ Import Namespace="SNFields=SenseNet.ContentRepository.Fields" %>
 
<asp:HyperLink ID="HyperLink1" runat="server" 
    ImageUrl ='<%# ((SNFields.HyperLinkFieldSetting)((SNControls.HyperLink)Container).Field.FieldSetting).UrlFormat == SNFields.UrlFormat.Picture 
        ? DataBinder.Eval(Container, "Data.Href") 
        : string.Empty %>'
    NavigateUrl='<%# DataBinder.Eval(Container, "Data.Href") %>'
    Text='<%# DataBinder.Eval(Container, "Data.Text") %>'
    ToolTip='<%# DataBinder.Eval(Container, "Data.Title") %>'
    Target='<%# DataBinder.Eval(Container, "Data.Target") %>'
    CssClass='<%# ((SNFields.HyperLinkFieldSetting)((SNControls.HyperLink)Container).Field.FieldSetting).UrlFormat == SNFields.UrlFormat.Picture ? "sn-listgrid-image" : string.Empty %>' />

Edit view template

<%@  Language="C#" %>
<%@ Import Namespace="SNControls=SenseNet.Portal.UI.Controls" %>
<%@ Import Namespace="SNFields=SenseNet.ContentRepository.Fields" %>
 
<table class='<%# "sn-ctrl-hyperlink" + (((SNControls.HyperLink)Container).Field.Name != "DefaultValue" && ((SNFields.HyperLinkFieldSetting)
    ((SNControls.HyperLink)Container).Field.FieldSetting).UrlFormat == SNFields.UrlFormat.Picture ? " sn-ctrl-imagelink" : "")  %>'>
    <tr>
        <td>
            <asp:Label ID="HrefLabel" AssociatedControlID="_href_" runat="server" />
        </td>
        <td>
            <asp:TextBox ID="_href_" runat="server" />
        </td>
    </tr>
    <tr runat="server" visible='<%# ((SNControls.HyperLink)Container).Field.Name == "DefaultValue" || 
        ((SNFields.HyperLinkFieldSetting)((SNControls.HyperLink)Container).Field.FieldSetting).UrlFormat != SNFields.UrlFormat.Picture %>'>
        <td>
            <asp:Label ID="TextLabel" AssociatedControlID="_text_" runat="server" />
        </td>
        <td>
            <asp:TextBox ID="_text_" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="LinkLabel" AssociatedControlID="_title_" runat="server" />
        </td>
        <td>
            <asp:TextBox ID="_title_" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="TargetLabel" AssociatedControlID="_target_" runat="server" />
        </td>
        <td>
            <asp:TextBox ID="_target_" runat="server" CssClass='<%# "sn-hyperlink-" + ((SNControls.HyperLink)Container).Field.Name.Replace("#", "") %>' /> <br />
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
            <span class="target-type-link" onclick='<%# string.Format("javascript:SetTarget(this, \"{0}\");", ((SNControls.HyperLink)Container).Field.Name.Replace("#", "")) %>
                ' title='<%=HttpContext.GetGlobalResourceObject("FieldControlTemplates", "BlankTitle")%>'><%=HttpContext.GetGlobalResourceObject("FieldControlTemplates", "Blank")%></span>, 
            <span class="target-type-link" onclick='<%# string.Format("javascript:SetTarget(this, \"{0}\");", ((SNControls.HyperLink)Container).Field.Name.Replace("#", "")) %>
                ' title='<%=HttpContext.GetGlobalResourceObject("FieldControlTemplates", "SelfTitle")%>'><%=GetGlobalResourceObject("FieldControlTemplates", "Self")%></span>, 
            <span class="target-type-link" onclick='<%# string.Format("javascript:SetTarget(this, \"{0}\");", ((SNControls.HyperLink)Container).Field.Name.Replace("#", "")) %>
                ' title='<%=HttpContext.GetGlobalResourceObject("FieldControlTemplates", "ParentTitle")%>'><%=GetGlobalResourceObject("FieldControlTemplates", "Parent")%></span>, 
            <span class="target-type-link" onclick='<%# string.Format("javascript:SetTarget(this, \"{0}\");", ((SNControls.HyperLink)Container).Field.Name.Replace("#", "")) %>
                ' title='<%=HttpContext.GetGlobalResourceObject("FieldControlTemplates", "TopTitle")%>'><%=GetGlobalResourceObject("FieldControlTemplates", "Top")%></span>, 
 
            <%=GetGlobalResourceObject("FieldControlTemplates", "FrameName")%>
        </td>
    </tr>
</table>
 
<script type="text/javascript" language="javascript">
    function SetTarget(link, fieldName) {
        $('.sn-hyperlink-' + fieldName).val(link.innerHTML);
    }
</script>
<style type="text/css">
    .target-type-link
    {
            cursor:pointer;color: Blue;text-decoration: underline
        }
</style>

Examples

Simple example

   <sn:hyperlink ID="hyperlink1" runat="server" FieldName="hyperlink1" />

Templated example

   <sn:hyperlink ID="hyperlink1" runat="server" FieldName="hyperlink1">
      <EditTemplate>
         <asp:TextBox ID="_href_" runat="server"></asp:TextBox>
         <asp:TextBox ID="_text_" runat="server"></asp:TextBox>
         <asp:TextBox ID="_title_" runat="server"></asp:TextBox>
         <asp:TextBox ID="_target_" runat="server"></asp:TextBox>
      </EditTemplate>
   </sn:hyperlink>

Related links

References