Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David 28 posts 156 karma points
    Oct 29, 2014 @ 12:07
    David
    0

    Contact Control doesn't work!

    Hello Comunity,

    i'm using umbraco version 7.1.8 for a week now and I've got a problem.

    I'm trying to add a contact control to my contact page and everytime I'm clicking on the send button nothing is going to be send.

    The problem is that if I click on the button, the btn_Send method doesnt get invoked.

    What i tried?
    - aspbutton with onclick
    - deactivated all scripts/styles

    In Umbraco I've added a macro which is refrenced to the ascx file.
    My contactpage has a richtext editor where ive added this macro.

     

    What am I doing wrong? Code below!
    Thank you for helping me!

    This is my ascx file.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Kontaktformular.ascx.cs" Inherits="Controls_Kontaktformular" %>
    
    <form runat="server">
        <asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <h1>Kontakt</h1>
                <h2>Postanschrift</h2>
                <h2>Telefon</h2>
    
                <h2>Kontaktformular</h2>
                <p>
                    Sie können uns mit dem Kontaktformular rund um die Uhr erreichen -
                wir antworten schnell und kompetent.
                </p>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                             <label>Name</label>
                            <asp:TextBox ID="BoxName" runat="server" placeholder="Vorname"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6"
                                ControlToValidate="BoxName"
                                Display="Dynamic"
                                Text="Ein Vorname ist erforderlich."
                                runat="server" />
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Email Address</label>
                            <asp:TextBox ID="BoxEMail" runat="server" class="display" placeholder="Email"></asp:TextBox>
                            <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator5"
                                ControlToValidate="BoxEMail"
                                Text="Eine gültige E-Mail Adresse ist nötig."
                                runat="server" />--%>
                            <br />
                            <%-- MailBox bezieht sich auf textbox ID!! Dieses Feld wird überprüft!  --%>
                            <%--<asp:RegularExpressionValidator ID="regexEmailValid" runat="server"
                                ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="BoxEMail"
                                ErrorMessage="Ungültige Email"></asp:RegularExpressionValidator>--%>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Ort</label>
                            <asp:TextBox ID="BoxOrt" runat="server" class="display" placeholder="Ort"></asp:TextBox>
                            <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
                                ControlToValidate="BoxOrt"
                                Text="Ein Nachname ist erforderlich."
                                runat="server" />--%>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Phone Number</label>
                            <asp:TextBox ID="BoxTelefon" runat="server" class="display" placeholder="Telfonnummer"></asp:TextBox>
                            <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                                ControlToValidate="BoxTelefon"
                                Text="Ein Nachname ist erforderlich."
                                runat="server" />--%>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Message</label>
                            <asp:TextBox ID="BoxNachricht" runat="server" TextMode="MultiLine" placeholder="Nachricht" class="display"></asp:TextBox>
                            <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
                                ControlToValidate="BoxNachricht"
                                Text="Eine Nachricht ist erforderlich."
                                runat="server" />--%>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <br>
                    <div id="success"></div>
                    <div class="row">
                        <div class="form-group col-xs-12">
                            <asp:Button Text="Send it" runat="server" ID="btnSend" />
    
                        </div>
                    </div>
            </div>
        </div>
    </div>
    </form>

    This is the code behind.

    public partial class Controls_Kontaktformular : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.EnableViewState = true;
            btnSend.Click += btnSend_Click;
        }
        void btnSend_Click(object sender, EventArgs e)
        {
            MailMessage message = new MailMessage(
               "[email protected]",
               BoxEMail.Text,
               "Quarterly data report.",
               GetMsgTxt()
               );
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("connect.aa-g.de");
            client.Send(message);
        }
    
        public string GetMsgTxt()
        {
            string msgtxt = "";
    
            msgtxt += "Von: " + BoxName.Text;
            msgtxt += "Nachricht: " + BoxNachricht.Text + " ";
            msgtxt += "Ort: " + BoxOrt.Text + " ";
            msgtxt += "Ort: " + BoxEMail.Text + " ";
            msgtxt += "Telefonnummer: " + BoxTelefon.Text;
            return msgtxt;
        }
    

    }

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Oct 30, 2014 @ 16:56
    Jan Skovgaard
    100

    Hi David and welcome to our :)

    Seems like you're using a webforms user control?

    Unless you have changed the template engine to run in webforms mode nothing will happen. By default in v7 MVC is being used. Carlos Martinez have written a tutorial on how to create a contact form using MVC in Umbraco here http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-contact-form/

    Hope this helps!

    /Jan

  • David 28 posts 156 karma points
    Oct 31, 2014 @ 11:04
    David
    0

    Hi Jan,

    thank you very much for your answer!

    Yes I'm using a webforms user control and I fixed it now!
    I just changed the following line in the umbracoSettings.config to:

    <defaultRenderingEngine>WebForms</defaultRenderingEngine>

    And I created a new template where i just pasted the old template code in. This works!
    Thank you again! :)

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Oct 31, 2014 @ 11:41
    Jan Skovgaard
    0

    Hi David

    Yeah, that's an option - But not advisable if you have been building a lot on a site already :) And I don't think it's that's it's future proof since the trend is leaning more and more towards to MVC rather than using WebForms.

    But if you just started out and have not done that much on your site yet then it's a fine solution for now. But when the time is right for you I think you'll benefit from learning to use MVC rather than WebForms.

    Remember to mark the topic as solved so others can benefit btw :)

    Cheers, Jan

Please Sign in or register to post replies

Write your reply to:

Draft