1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom Forms (Newbie)

Custom Forms (Newbie)

8 posts, 0 answered
  1. Susan
    Susan avatar
    7 posts
    Registered:
    21 Dec 2008
    03 Feb 2009
    Link to this post
    What is the best strategy for adding a custom form to a Community site?  I need to add a simple "Contact Us" sort of form.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Feb 2009
    Link to this post
    Hello Susan,

    Sitefinity is ASP.NET application so you can create a user control which will send the messages to your email through the website.

    Here is a sample:

    control template:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactUs.ascx.cs" Inherits="CustomControls_ContactUs" %> 
     
    <h3><asp:Label ID="Label1" runat="server" Text="Contact us"></asp:Label><br /></h3
    <asp:Label ID="Label2" runat="server" Text="Your name:"></asp:Label> 
    <asp:TextBox ID="txtName" runat="server" ></asp:TextBox><br /> 
    <asp:Label ID="Label3" runat="server" Text="Your mail:"></asp:Label> 
    <asp:TextBox ID="txtEmail" runat="server" ></asp:TextBox><br /> 
    <asp:Label ID="Label4" runat="server" Text="TextMessage:"></asp:Label> 
    <asp:TextBox ID="txtMessage" runat="server" Rows="5" TextMode="MultiLine" ></asp:TextBox><br /> 
     
    <asp:Button ID="buttonSend" runat="server" Text="SendMessage"  
        onclick="buttonSend_Click" /> 


    and the code behind:

    using System; 
    using System.Web.Mail;.System.Data; 
    using System.Collections.Generic; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Net.Mail; 
    using System.Web.Mail; 
     
    public partial class CustomControls_ContactUs : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
        } 
     
        public string ToEmail 
        { 
            get { return this.toEmail;} 
            setthis.ToEmail = value;} 
        } 
        public string SmtpServer 
        { 
            get{return this.smtpServer;} 
            set{this.smtpServer = value;} 
        } 
     
        protected void buttonSend_Click(object sender, EventArgs e) 
        { 
            MailMessage mail = new MailMessage(); 
            mail.From = txtEmail.Text; 
            mail.To = this.ToEmail; 
            mail.Subject = "contact form message"
            mail.Body = String.Concat(txtName.Text, "-", txtMessage.Text); 
            SmtpMail.SmtpServer = this.smtpServer; 
            SmtpMail.Send(mail); 
        } 
        private string toEmail; 
        private string smtpServer; 

    I hope this helps.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Susan
    Susan avatar
    7 posts
    Registered:
    21 Dec 2008
    04 Feb 2009
    Link to this post
    Thank you, love the product!
  4. Harry
    Harry avatar
    23 posts
    Registered:
    07 Aug 2008
    06 Nov 2009
    Link to this post
    I've create a custom form similar to the one above. Adding it to a page is no problem.

    When I click edit to supply an email address or an SMTP server, the screen loads correctly, but when trying to save, the system just hangs. Eventually after a while, Windows / IIS disables the ASP.NET Classi AppPool.

    Any idea what's going on?

    Harry
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Nov 2009
    Link to this post
    Hi Harry,

    Check whether the code you use does not cause crashing of the IIS server - stack overflow or system out of memory exception. You can use Visual Studio ASP.NET Web server to catch the error easily.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Webteam
    Webteam avatar
    28 posts
    Registered:
    30 Nov 2009
    05 Jan 2010
    Link to this post
    The same error here.  I get the system out of memory error and infinite loop warning.  The code halts at this line:
    public string ToEmail
        {
            get { return this.toEmail; }
            set { this.ToEmail = value; }  // here
        }
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Jan 2010
    Link to this post
    Hello David Desjardins,

    Try using the user control that is shown below. There is a typo in the property that causes the problem.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net.Mail;
    using System.Web.Mail;
     
    public partial class CustomControls_ContactUs : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            buttonSend.Click += new EventHandler(buttonSend_Click);
        }
     
        void buttonSend_Click(object sender, EventArgs e)
        {
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(txtEmail.Text, ToEmail);
            mail.Subject = "contact form message";
            mail.Body = String.Concat(txtName.Text, "-", txtMessage.Text);
            SmtpClient client = new SmtpClient(smtpServer);
            client.Send(mail);
     
        }
     
        public string ToEmail
        {
            get { return this.toEmail; }
            set { this.toEmail = value; }
        }
        public string SmtpServer
        {
            get { return this.smtpServer; }
            set { this.smtpServer = value; }
        }
     
       
        private string toEmail;
        private string smtpServer;
    }


    <h3><asp:Label ID="Label1" runat="server" Text="Contact us"></asp:Label><br /></h3>
    <asp:Label ID="Label2" runat="server" Text="Your name:"></asp:Label>
    <asp:TextBox ID="txtName" runat="server" ></asp:TextBox><br />
    <asp:Label ID="Label3" runat="server" Text="Your mail:"></asp:Label>
    <asp:TextBox ID="txtEmail" runat="server" ></asp:TextBox><br />
    <asp:Label ID="Label4" runat="server" Text="TextMessage:"></asp:Label>
    <asp:TextBox ID="txtMessage" runat="server" Rows="5" TextMode="MultiLine" ></asp:TextBox><br />
      
    <asp:Button ID="buttonSend" runat="server" Text="SendMessage" />


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Webteam
    Webteam avatar
    28 posts
    Registered:
    30 Nov 2009
    30 Apr 2010
    Link to this post
    Many thanks.
Register for webinar
8 posts, 0 answered