Hi all, I have createde a basic user control with, textbox, textarea, and button the code is working, and there is no error. But when i press the button send it dosent do anything, on button click event am i missing something?
any idea?
What I wantis that the customer to fill out the formandsend it toanemail.
here is my code.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="KontaktFormular.ascx.cs" Inherits="UserControls_KontaktFormular" %>
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;
public partial class UserControls_KontaktFormular : System.Web.UI.UserControl {
If you're running Umbraco 7 out of the box it's using MVC rather then webforms. It means that when you need to trigger a webform it won't work - however as you have noticed the webform will be displayed etc. - But the events won't be triggered.
If it's a big site that you have done a lot of development on it's probably not an option to change the template mode from MVC to Webforms - But if you're just playing around with some code then you can change it in the /config/umbracoSettings.config file in the
However I personally think it's better to ditch webforms and learn MVC since I think that the support of WebForms might be discontinued in future versions of Umbraco.
User control - ASCX does not send email
Hi all,
I have createde a basic user control with, textbox, textarea, and button
the code is working, and there is no error. But when i press the button send
it dosent do anything, on button click event am i missing something?
any idea?
What I want is that the customer to fill out the form and send it to an email.
here is my code.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="KontaktFormular.ascx.cs" Inherits="UserControls_KontaktFormular" %>
<h3>Kontakt- formular</h3>
<form runat="server">
<fieldset>
<label for="nameTxt">Name:</label>
<input type="text" id="txtName" name="text1" />
<label for="emailTxt:">Email:</label>
<input type="text" id="txtEmail" name="email" />
<label for="messageTxt">Besked</label>
<textarea runat="server" id="txtMessage" rows="7" cols="24"></textarea>
<Button ID="Button1" runat="server" Text="btnSubmit" onclick="Button1_Click" />
</fieldset>
</form>
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;
public partial class UserControls_KontaktFormular : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(Object sender, EventArgs e)
{
string getNameValues = Page.Request.Form["text1"].ToString();
string getEmailValues = Page.Request.Form["email"].ToString();
string getMessageValues = Page.Request.Form["txtMessage"].ToString();
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(getEmailValues);
mail.To.Add("[email protected]");
mail.IsBodyHtml = true;
mail.Body += "Name: " + getNameValues + "<br /><br /> ";
mail.Body += "Mail: " + getEmailValues + "<br /><br />";
mail.Body += "Message: " + getMessageValues + "<br /><br />";
SmtpClient smtp = new SmtpClient();
smtp.Host = "";
smtp.Send(mail);
Response.Redirect("success.html");
}
catch
{
Response.Redirect("failure.html");
}
}
}
Hi Princess
If you're running Umbraco 7 out of the box it's using MVC rather then webforms. It means that when you need to trigger a webform it won't work - however as you have noticed the webform will be displayed etc. - But the events won't be triggered.
If it's a big site that you have done a lot of development on it's probably not an option to change the template mode from MVC to Webforms - But if you're just playing around with some code then you can change it in the /config/umbracoSettings.config file in the
However I personally think it's better to ditch webforms and learn MVC since I think that the support of WebForms might be discontinued in future versions of Umbraco.
You can read a bit more about moving from Webforms to MVC here http://umbraco.com/follow-us/blog-archive/2013/7/14/moving-from-webforms-to-mvc.aspx
Even though this article is a bit old some of the concepts are still true today http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
And you might also enjoy this blogpost from Warren http://creativewebspecialist.co.uk/2013/07/17/umbraco-mvc-first-steps/
Hope this helps.
/Jan
Hi again
Perhaps you can also benefit from this post http://our.umbraco.org/forum/core/general/40658-Migrating-from-Web-forms-to-MVC
/Jan
is working on a reply...