Chcę wykonać podstawową funkcjonalność za pomocą prostego formularza kontaktowego i po przesłaniu wiadomości e-mail do innej osoby. Jest to dość łatwe do zrobienia w asp.net, jednak mam problemy, gdy raz go załaduję jako kontrolę użytkownika. Czy masz dobry przykład, na który mogę patrzeć? Dziękuję Ci!Formularz kontaktowy w SiteFinity C#
Odpowiedz
To jest to samo, co na normalnej stronie asp.net, przy założeniu, że używasz najnowszej wersji Sitefinity i masz RadScriptManager lub ScriptManager na swojej stronie wzorcowej.
Po pierwsze tu jest mój przykład forma codebehind:
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.Text;
using System.ComponentModel;
public partial class UserControls_LandingPage_contactForm : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
bool bSent = false;
try
{
//create the email and add the settings
var email = new MailMessage();
email.From = new MailAddress(FromEmail);
email.To.Add(new MailAddress(FromEmail));
email.Subject = Subject;
email.IsBodyHtml = true;
//build the body
var sBody = new StringBuilder();
sBody.Append("<strong>Contact Details</strong><br /><br />");
sBody.AppendFormat("Needs: {0}<br />", cboConsultationType.SelectedValue);
sBody.AppendFormat("Name: {0}<br />", txtName.Text);
sBody.AppendFormat("Email: {0}<br />", txtEmail.Text);
sBody.AppendFormat("Number: {0}<br />", txtPhone.Text);
sBody.AppendFormat("Comment: {0}<br />", txtMsg.Text);
email.Body = sBody.ToString();
//send the email
var smtpServer = new SmtpClient();
smtpServer.Send(email);
//mark as sent ok
bSent = true;
}
catch (Exception ex)
{
//send any errors back
//add your own custom handling of errors;
}
//let the end user know if it was a success
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + (bSent ? SuccessText : FailureText) + "');", true);
}
//properties
public string FromEmail
{
get { return _fromEmail; }
set { _fromEmail = value; }
}
public string Subject
{
get { return _subject; }
set { _subject = value; }
}
public string SuccessText
{
get { return _successText; }
set { _successText = value; }
}
public string FailureText
{
get { return _failureText; }
set { _failureText = value; }
}
//fields
private string _fromEmail = "[email protected]";
private string _subject = "Website Enquiry";
private string _successText = "Thank you for submitting your details we will be in touch shortly.";
private string _failureText = "There was a problem submitting your details please try again shortly.";
}
Kod ASCX:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="UserControls_LandingPage_contactForm" %>
<fieldset>
<div class="focus">
<label>
I need...</label>
<asp:DropDownList ID="cboConsultationType" runat="server" CssClass="select sub web">
<asp:ListItem Value="I Need A New Web Site">A completely new website</asp:ListItem>
<asp:ListItem Value="Web Site Upgrade">My website upgraded</asp:ListItem>
<asp:ListItem Value="Application Design">An application </asp:ListItem>
<asp:ListItem Value="An ecommerce website">New Ecommerce website</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
</div>
<ul>
<li>
<asp:Label EnableViewState="false" ID="lblErrorMessage" runat="server"></asp:Label>
</li>
<li>
<asp:Label EnableViewState="false" ID="lblName" AssociatedControlID="txtName" runat="server"
Text="Name"></asp:Label>
<asp:TextBox ID="txtName" runat="server" ValidationGroup="ContactValidation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ValidationGroup="ContactValidation"
ControlToValidate="txtName" ErrorMessage="Name is required">*</asp:RequiredFieldValidator>
</li>
<li>
<asp:Label ID="lblPhone" runat="server" AssociatedControlID="txtPhone" EnableViewState="false"
Text="Phone"></asp:Label>
<asp:TextBox ID="txtPhone" runat="server" ValidationGroup="ContactValidation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorPhone" runat="server" ValidationGroup="ContactValidation"
ControlToValidate="txtPhone" ErrorMessage="Phone is required">*</asp:RequiredFieldValidator>
</li>
<li>
<asp:Label ID="lblEmail" runat="server" AssociatedControlID="txtEmail" EnableViewState="false"
Text="Email"></asp:Label>
<asp:TextBox ID="txtEmail" runat="server" ValidationGroup="ContactValidation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="ContactValidation"
ControlToValidate="txtEmail" ErrorMessage="Email is required">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorEmail" runat="server"
ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="ContactValidation" ErrorMessage="Email address is invalid">*</asp:RegularExpressionValidator>
</li>
<li>
<asp:Label ID="lblMsg" runat="server" AssociatedControlID="txtMsg" EnableViewState="false"
Text="How can we assist you?"></asp:Label>
<asp:TextBox ID="txtMsg" runat="server" TextMode="MultiLine" Rows="5" Wrap="true"></asp:TextBox>
</li>
<li>
<asp:Button ID="btnSubmit" runat="server" EnableViewState="false" CssClass="submit"
Text="Send" ValidationGroup="ContactValidation" OnClick="btnSubmit_Click" />
</li>
</ul>
</fieldset>
wówczas jedynym inne przedmioty, które trzeba uważać na to w pliku web.config trzeba zmodyfikować ustawienia systemowe.net: e-mail:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.yourdomain.com" userName="Your_Username" password="Your_Password" port="25" />
</smtp>
</mailSettings>
</system.net>
Następnie prześlij kontrolę lub zmodyfikuj swój plik web.config. Następnie pod warunkiem, że twój serwer SMTP jest poprawnie skonfigurowany, formularz nie powinien wysyłać żadnych problemów.
Mam nadzieję, że to pomoże.
Myślę, że dobrym podejściem jest korzystanie z wbudowanego nadawcy poczty. Zyski są takie, że można skonfigurować ustawienia wewnątrz Administracja-> Ustawienia-> Zaawansowane-> System-> SMTP
var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;
MailMessage message = new MailMessage();
message.From = new MailAddress(smtpSettings.UserName);
message.To.Add(new MailAddress(toEmail));
StringBuilder sb = new StringBuilder();
sb.AppendFormat(body);
message.Subject = subject;
message.Body = sb.ToString();
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.Unicode;
message.SubjectEncoding = Encoding.Unicode;
EmailSender.Get().Send(message);
Można używać powiadomień zbyt.
- 1. Formularz kontaktowy w Rails 3
- 2. Formularz kontaktowy w ruby, sinatrze i haml
- 3. Formularz kontaktowy 7 automatycznego dodania tagów p
- 4. (Wordpress) Formularz kontaktowy 7 Przerwij filtr before_send_mail
- 5. Formularz kontaktowy Nie ma odpowiedzi na wysyłanie wiadomości e-mail?
- 6. Formularz kontaktowy do wiadomości e-mail bez PHP
- 7. Box2dweb - Punkt kontaktowy kolizji
- 8. Formularz utracił ostrość w C#
- 9. Ukryj formularz internetowy w drupalu 7
- 10. Jak zamknąć formularz w języku C#
- 11. Formularz Windows w nieregularnym kształcie (C#)
- 12. Dlaczego ten formularz jest poprawny w C?
- 13. Jak utworzyć formularz "unfocusable" w języku C#?
- 14. Dlaczego formularz VB6.0 jest wyświetlany jako formularz C#?
- 15. Błąd 401 Dzwoniąc z Web Services Sitefinity WCF
- 16. Jak złożyć formularz http za pomocą C#
- 17. Pokaż formularz dziecka w centrum postaci dominującej w C#
- 18. C# skopiować, wkleić formularz w projekcie Visual Studio
- 19. Adres IP w C++ czytelny dla człowieka formularz
- 20. Poprawny formularz do plasterka tablicy w języku C#
- 21. C# jak wyświetlić formularz w określonej pozycji myszy na ekranie?
- 22. Czy istnieje parser wieloczęściowy/formularz danych w C# - (NO ASP)
- 23. Formularz wejściowy w przecenach
- 24. Jak mogę zaimplementować formularz wejściowy html bez backendu
- 25. Jak uzyskać konkretny numer kontaktowy za pomocą identyfikatora kontaktu
- 26. Formularz Windows z konsoli
- 27. Formularz centralny przy starcie
- 28. Formularz sprawdzania poprawności w django
- 29. Jak odrzucić formularz w angular2
- 30. Jak wydrukować formularz w Delphi?
Świetna odpowiedź, Sean! – Slavo
Dzięki Sean! Bardzo pomocne :-) –
Nie ma problemu Myślę, że musisz oznaczyć moją jako odpowiedź, pod warunkiem oczywiście uważasz, że to było słuszne;) –