|
|
| D: | Domains | Authors.aspalliance.com | Stevesmith | Articles | A Feedback Form in ASP.NET |
|
A Feedback Form in ASP.NET [Example]
It's very easy to build an email form in ASP.NET. So easy, in fact, that I'm not going to waste a whole lot of time on the object model or other low level considerations. Instead, I'm just going to present the code and let you use it as you see fit. You can click on the Example link above, but please only submit the form if you are actually intent on becoming a writer for ASPAlliance.com. I get enough junk mail from losers after free web hosting as it is... join.aspx1 <%@ Page language="c#" Codebehind="join.aspx.cs" AutoEventWireup="false" Inherits="ASPAlliance.Pages.join" Trace="false" Debug="false" %> 2 <%@ Register TagPrefix="SSTemplate" tagname="showHeader" 3 src="/controls/showHeader.ascx"%> 4 <%@ Register TagPrefix="SSTemplate" tagname="showFooter" 5 src="/controls/showFooter.ascx"%> 6 <SSTemplate:showHeader id="header" title="Become a Columnist" runat="server" /> 7 <form method="post" runat="server"> 8 <br> 9 <b>Become an ASPAlliance Columnist!</b> 10 <P> 11 If you think you would make a valuable addition to the ASP Alliance as a 12 columnist, please fill out the form below. In the box provided, please copy and 13 paste a complete article that you would post on your column. This article will 14 be reviewed by our columnists. If we accept it, you will become an ASPAlliance 15 columnist. 16 </P> 17 <P> 18 <B>This is not just free web space! You must be willing to publish quality articles 19 related to ASP, .NET, or other Internet technologies.</B></P> 20 <P> 21 <B>ASPAlliance lets you retain ownership and copyright of all of your material!</B>You 22 can submit it to other sites, publish it in articles, and basically do whatever 23 you want with it. However, ASPAlliance will keep unmodified copies of your 24 articles indefinitely as a service to our readers. 25 </P> 26 <P> 27 Some of the benefits of being an AspAlliance.com columnist include free web 28 hosting with ASP and ASP.NET support, SQL Server access (SQL2000), and a POP3 29 mail account, if desired. You're welcome to promote yourself as an author or 30 developer or whatever you like, provided that your column provides value to 31 AspAlliance visitors as well. Columnists are encouraged to display ads on their 32 sites, which help support the site and provide modest royalties to the 33 columnists. Also, all columnist sites must include a reference to the 34 ASPAlliance, and by publishing material on this site, you grant ASPAlliance.com 35 the right to host such material indefinitely, regardless of whether or not you 36 remain a member/columnist (as noted above). 37 </P> 38 <table border="1" bordercolor="red" cellspacing="0" cellpadding="2"> 39 <tr> 40 <td width="336"> 41 Full Name 42 </td> 43 <td> 44 <asp:textbox id="fullname" runat="Server"></asp:textbox> 45 </td> 46 <td> 47 <asp:requiredfieldvalidator id="fullname_required" runat="Server" controltovalidate="fullname" errormessage="Full name is required."></asp:requiredfieldvalidator> 48 </td> 49 </tr> 50 <tr> 51 <td width="336"> 52 How long have you been developing dynamic Internet applications? 53 </td> 54 <td> 55 <asp:dropdownlist id="howlong" runat="Server"> 56 <asp:listitem value=""></asp:listitem> 57 <asp:listitem value="Just Starting"></asp:listitem> 58 <asp:listitem value="1-3 Months"></asp:listitem> 59 <asp:listitem value="4-6 Months"></asp:listitem> 60 <asp:listitem value="6-12 Months"></asp:listitem> 61 <asp:listitem value="Over a Year"></asp:listitem> 62 <asp:listitem value="Too Long ;) "></asp:listitem> 63 </asp:dropdownlist> 64 </td> 65 <td> 66 <asp:requiredfieldvalidator id="howlong_required" runat="Server" controltovalidate="howlong" errormessage="Please select an item from the list."></asp:requiredfieldvalidator> 67 </td> 68 </tr> 69 <tr> 70 <td width="336"> 71 Email 72 </td> 73 <td> 74 <asp:textbox id="email" runat="server" width="150"></asp:textbox> 75 </td> 76 <td> 77 <asp:requiredfieldvalidator id="email_required" runat="Server" controltovalidate="email" errormessage="Email is required."></asp:requiredfieldvalidator> 78 </td> 79 </tr> 80 <tr> 81 <td width="336"> 82 <P>Requested Username / Folder name<br> 83 This is used both for your login to the site and as your folder name, e.g. 84 www.aspalliance.com/folder/. This will also be used as your POP3 account, if 85 you request one. 86 </P> 87 </td> 88 <td> 89 <asp:textbox id="username" runat="server" width="150"></asp:textbox> 90 </td> 91 <td> 92 <asp:requiredfieldvalidator id="username_required" runat="Server" controltovalidate="username" errormessage="A username/foldername is required."></asp:requiredfieldvalidator> 93 </td> 94 </tr> 95 <tr> 96 <td width="336"> 97 Requested POP Account (username@aspalliance.com) 98 </td> 99 <td> 100 <asp:dropdownlist id="pop_requested" runat="Server"> 101 <asp:listitem value=""></asp:listitem> 102 <asp:listitem value="No, I don't need a POP account."></asp:listitem> 103 <asp:listitem value="Yes, please give me a POP account."></asp:listitem> 104 </asp:dropdownlist> 105 </td> 106 <td> 107 <asp:requiredfieldvalidator id="pop_requested_required" runat="Server" controltovalidate="pop_requested" errormessage="You must select Yes or No."></asp:requiredfieldvalidator> 108 </td> 109 </tr> 110 <tr> 111 <td width="336"> 112 Requested Access Method 113 </td> 114 <td> 115 <asp:listbox id="access" runat="Server" selectionmode="Multiple"> 116 <asp:ListItem Value="FTP">FTP</asp:ListItem> 117 <asp:ListItem Value="Frontpage Server Extensions (FPSE)">Frontpage Server Extensions 118 (FPSE)</asp:ListItem> 119 </asp:listbox> 120 </td> 121 <td> 122 <asp:requiredfieldvalidator id="access_required" runat="Server" controltovalidate="access" errormessage="Please select at least one access method."></asp:requiredfieldvalidator> 123 </td> 124 </tr> 125 <tr> 126 <td width="336"> 127 Sample Article 128 </td> 129 <td> 130 <asp:textbox id="sample" runat="Server" textmode="MultiLine" rows="10" columns="60"></asp:textbox> 131 </td> 132 <td> 133 <asp:requiredfieldvalidator id="sample_required" runat="Server" controltovalidate="sample" errormessage="A sample article is required."></asp:requiredfieldvalidator> 134 </td> 135 </tr> 136 </table> 137 <asp:button id="btnSubmit" text="Send" runat="Server"></asp:button> 138 <p> 139 How does this page work? Click <a href="http://www.aspalliance.com/stevesmith/articles/how_join.asp"> 140 here</a> to see! 141 </p> 142 </form> 143 <SSTemplate:showFooter id="footer" runat="server" /> join.aspx.cs 1 namespace ASPAlliance.Pages 2 { 3 using System; 4 using System.Web.Mail; 5 using System.Collections; 6 using System.ComponentModel; 7 using System.Data; 8 using System.Drawing; 9 using System.Web; 10 using System.Web.SessionState; 11 using System.Web.UI; 12 using System.Web.UI.WebControls; 13 using System.Web.UI.HtmlControls; 14 15 /// <summary> 16 /// Summary description for join. 17 /// </summary> 18 public class join : System.Web.UI.Page 19 { 20 protected System.Web.UI.WebControls.Button btnSubmit; 21 protected System.Web.UI.WebControls.RequiredFieldValidator sample_required; 22 protected System.Web.UI.WebControls.TextBox sample; 23 protected System.Web.UI.WebControls.RequiredFieldValidator access_required; 24 protected System.Web.UI.WebControls.ListBox access; 25 protected System.Web.UI.WebControls.RequiredFieldValidator pop_requested_required; 26 protected System.Web.UI.WebControls.DropDownList pop_requested; 27 protected System.Web.UI.WebControls.RequiredFieldValidator username_required; 28 protected System.Web.UI.WebControls.TextBox username; 29 protected System.Web.UI.WebControls.RequiredFieldValidator email_required; 30 protected System.Web.UI.WebControls.TextBox email; 31 protected System.Web.UI.WebControls.RequiredFieldValidator howlong_required; 32 protected System.Web.UI.WebControls.DropDownList howlong; 33 protected System.Web.UI.WebControls.RequiredFieldValidator fullname_required; 34 protected System.Web.UI.WebControls.TextBox fullname; 35 36 public join() 37 { 38 Page.Init += new System.EventHandler(Page_Init); 39 } 40 41 protected void Page_Load(object sender, EventArgs e) 42 { 43 if (!IsPostBack) 44 { 45 // 46 // Evals true first time browser hits the page 47 // 48 } 49 } 50 51 protected void Page_Init(object sender, EventArgs e) 52 { 53 // 54 // CODEGEN: This call is required by the ASP+ Windows Form Designer. 55 // 56 InitializeComponent(); 57 } 58 59 /// <summary> 60 /// Required method for Designer support - do not modify 61 /// the contents of this method with the code editor. 62 /// </summary> 63 private void InitializeComponent() 64 { 65 this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click); 66 this.Load += new System.EventHandler(this.Page_Load); 67 68 } 69 70 public void btnSubmit_Click (object sender, System.EventArgs e) 71 { 72 String message=""; 73 String access_methods=""; 74 int i; 75 if (Page.IsValid) { 76 Trace.Write("Submit", "Page is valid -- send email."); 77 message += "Full Name: " + fullname.Text + "\n"; 78 message += "How Long?: " + howlong.SelectedItem.Text + "\n"; 79 message += "Email: " + email.Text + "\n"; 80 message += "Request POP Account?: " + pop_requested.SelectedItem.Text + "\n"; 81 message += "Requested Username / Web name / POP3 Account(if requested): " + username.Text + "\n"; 82 message += "Requested Access Method(s): "; 83 for (i=0;i<access.Items.Count;i++) { 84 if(access.Items[i].Selected) { 85 if (access_methods!="") { 86 access_methods+=", "; 87 } 88 access_methods += access.Items[i].Text; 89 } 90 } 91 message += access_methods + "\n"; 92 message += "Sample Article: \n" + sample.Text; 93 MailMessage Mailer = new MailMessage(); 94 Mailer.From = email.Text; 95 Mailer.To = "columnist-join@aspalliance.com"; 96 Mailer.Subject = "ASPAlliance Join Request"; 97 Mailer.Body = message; 98 SmtpMail.SmtpServer = "localhost"; 99 SmtpMail.Send(Mailer); 100 Server.Transfer("jointhankyou.aspx"); 101 // Response.Redirect("jointhankyou.aspx"); 102 } 103 } 104 } 105 } Reference Links: |
|
|
|
|
|
|
|