views:

857

answers:

3

In sharepoint designer I have a control

<SharePointWebControls:TextField FieldName="Title" runat="server"></SharePointWebControls:TextField>

I want to have a mailto link that will use this title as the subject of the email and i need the body of the email to contain some text e.g. "My Example Text"

how do i do this?

thanks

A: 

It sounds to me as though, rather than a MailTo link you are looking for a contact form, perhaps something like this example would be useful, at least as something to look at. Also this Sharepoint contact form example could be worth a look.

glenatron
A: 

I would suggest creating a custom field class, that inherits from TextField and in the display mode creates the mailto tag.

public class EmailToTextField: Microsoft.SharePoint.WebControls.TextField
{
    public override void RenderControl(System.Web.UI.HtmlTextWriter writer)
    {
     switch (ControlMode)
     {
        case Microsoft.SharePoint.WebControls.SPControlMode.Display:
              writer.Write("<a href='mailto:" + Value + "?subject=" + Value + "&body=sometext'>EMAIL</a>");
              break;
        default:
              base.RenderControl(writer);
              break;
      }
   }
}

And then just add it as a safe control, and use it in code like this:

<MyWebControls:EmailToTextField FieldName="Title" runat="server"></MyWebControls:EmailToTextField>

Hope it helps

Paulo Oliveira
that's not a custom field, that's a user control
Jason
It's not a User Control. It's a custom field "Renderer" ... closer to a webpart than to a User Control actually
Paulo Oliveira
A: 

I would use the above given approach. The comment Jason gave is misleading - that code is in fact a custom field control. And yes, I guess custom field controls could be called user controls, since they are written in C#. I use similar custom field controls in my own solutions.