Julia Computer Consulting Form in ASP.NET
that posts to a new page and Access table

GO TO FORM DEMO THAT POSTS TO THE SAME PAGE

GO TO FORM DEMO THAT POSTS TO A NEW PAGE AND ACCESS TABLE

or those of you who have successfully installed ASP.NET on their servers or would like a tip from me on where to get it for six months for $50, will love this simple form.  There are two buttons, one posts to the same page and sends emails, the other posts to another page like a regular ASP formusing cookies.  The coloring and size of things are a combination of Stylesheets and in the functions themselves.

It has validations that are out of this world, posts to another page and posts to the database, and sends two emails. The database is now working.  The Access table is called Form.

For those of you who need an introduction to ASP.NET, I highly recommend ASP.NET for Dummies, available on amazon.com

Copy this code on Notepad to be sure you're getting the right elements. 

The code for cookie.aspx is beneath the code for newpage.aspx You need two aspx pages, one cookie.aspx and the other, the main page newpage.aspx..

Code for newpage.aspx

<%@Page Explicit="True" Language="VB" Debug="True"%>
<%@ Import Namespace="System.Data.Odbc" %>
<% @Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.Data" %>

 

<script runat="server">
Sub OKToNewPage(Sender As Object, E As EventArgs)

Header.Text="Your form results are: "
LabelOrg.Text=Org.Text
LabelEmail.Text=Email.Text
LabelEmail2.Text=Email2.Text
LabelName.Text=FullName.Text
LabelAddress.Text=Address.Text
LabelCity.Text=City.Text
LabelState.Text=State.Text
LabelZipCode.Text=ZipCode.Text
LabelHome.Text=HomePhone.Text
LabelWork.Text=WorkPhone.Text
LabelComments.Text=Comments.Value
Header.Font.Size=FontUnit.Point(14)
LabelOrg.Font.Size=FontUnit.Point(14)
LabelEmail.Font.Size=FontUnit.Point(14)
LabelEmail2.Font.Size=FontUnit.Point(14)
LabelName.Font.Size=FontUnit.Point(14)
LabelAddress.Font.Size=FontUnit.Point(14)
LabelCity.Font.Size=FontUnit.Point(14)
LabelState.Font.Size=FontUnit.Point(14)
LabelZipCode.Font.Size=FontUnit.Point(14)
LabelHome.Font.Size=FontUnit.Point(14)
LabelWork.Font.Size=FontUnit.Point(14)
LabelComments.Font.Size=FontUnit.Point(14)

 

If Email.Text<>"" AND FullName.Text<>"" AND HomePhone.Text<>"" Then

Dim objMM as New MailMessage()

'Set the properties
objMM.To = Email.Text
objMM.From = "julia@juliacomputers.com"

'If you want to CC this email to someone else...
objMM.Cc = "julia@juliacomputers.com"

'Send the email in text format
objMM.BodyFormat = MailFormat.Text
'(to send HTML format, change MailFormat.Text to MailFormat.Html)

'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal

'Set the subject
objMM.Subject = "Thank you for consulting Julia Computer Consulting LLC!"

objMM.Body="Thank you for consulting Julia Computer Consulting LLC! This is an example of a form written in ASP.Net, we also have forms available written in ASP(Active Server Pages) and ColdFusion custom-tailored to the client. Other programming projects have included ASP Ecommerce and Password Programs." & Chr(10) & Chr(10) & "Julia Computer Consulting is a Sole Proprietorship which has been successfully in business for the past five or six years. Please contact us at your earliest convenience. Our rates are very reasonable, and always open to discussion. Consultations are free." & Chr(10) & Chr(10) & "Thank you again..." & Chr(10) & Chr(10) & "Julia Computer Consulting LLC" & Chr(10) & "PO Box 279, Watertown MA 02471-0279" & Chr(10) & "Email: julia@juliacomputers.com" & Chr(10) & "URL: http://www.juliagreen.com"
SmtpMail.Send(objMM)

Dim objMM2 as New MailMessage()

'Set the properties
objMM2.To = Email.Text
objMM2.From = "julia@juliacomputers.com"

'If you want to CC this email to someone else...
objMM2.Cc = "julia@juliacomputers.com"

'Send the email in text format
objMM2.BodyFormat = MailFormat.Text
'(to send HTML format, change MailFormat.Text to MailFormat.Html)

'Set the priority - options are High, Low, and Normal
objMM2.Priority = MailPriority.Normal

'Set the subject
objMM2.Subject = "Form Results for ASP.NET Julia Computer Consulting LLC"

objMM2.Body="This form was submitted by " & Email.Text & " on " & Now & "." & Chr(10) & "*********************************************************" & Chr(10) & Chr(10) & "Organization: " & Org.Text & Chr(10) & Chr(10) & "Email: " & Email.Text & Chr(10) & Chr(10) & "URL: " & Email2.Text & Chr(10) & Chr(10) & "Full Name: " & FullName.Text & Chr(10) & Chr(10) & "Address: " & Address.Text & " " & City.Text & " " & State.Text & " " & ZipCode.Text & Chr(10) & Chr(10) & " " & "Home Phone: " & HomePhone.Text & Chr(10) & Chr(10) & "Work Phone: " & WorkPhone.Text & Chr(10) & Chr(10) & "Comments: " & Comments.Value

SmtpMail.Send(objMM2)
End If

 

dim dbconn,sql,dbcomm
dbconn=new ODBCConnection()
dbconn.ConnectionString="Dsn=yourdsn"
dbconn.Open()
'sql="INSERT INTO Form(FullName)VALUES('" & FullName.Text & "')"
sql="INSERT INTO Form (Org, email, Email2, FullName, Address, City, State, ZipCode, HomePhone, WorkPhone, Comments)VALUES('" & Org.Text & "','" & email.Text & "','" & Email2.Text & "','" & FullName.Text & "','" & Address.Text & "','" & City.Text & "','" & State.Text & "','" & ZipCode.Text & "','" & HomePhone.Text & "','" & WorkPhone.Text & "','" & Comments.Value & "')"
dbcomm=New ODBCCommand(sql,dbconn)
dbcomm.ExecuteNonQuery
dbconn.Close()

 

Dim Cookie As HttpCookie=New HttpCookie("Pref")

Cookie.Values.Add("Org", Org.Text)
Cookie.Values.Add("Email", Email.Text)
Cookie.Values.Add("Email2", Email2.Text)
Cookie.Values.Add("Name", FullName.Text)
Cookie.Values.Add("Address", Address.Text)
Cookie.Values.Add("City", City.Text)
Cookie.Values.Add("State", State.Text)
Cookie.Values.Add("ZipCode", ZipCode.Text)
Cookie.Values.Add("HomePhone", HomePhone.Text)
Cookie.Values.Add("WorkPhone", WorkPhone.Text)
Cookie.Values.Add("Comments", Comments.Value)
Cookie.Expires=#12/31/2010#

Response.Cookies.Add(Cookie)
Response.Redirect("http://www.juliagreen.com/cookie.aspx")

End Sub
</script>

<html>
<head>
<STYLE TYPE="text/css">
body { margin-left: .15in; margin-right: .25in; color: navy; font-size: 12pt}
h1 { text-align: center; color: navy; }
table {font-size:10pt; color: navy; }
fieldset { border: 3px ridge navy; padding: 6px; font-weight: bold; font-size: 10pt; color: blue; }
</STYLE>
</head>
<body bgcolor="white">
<br><br><br>
<h1>Julia Computer Consulting LLC ASP.NET Form</h1>
<br>Fill out this form as completely as possible. Email, Home Phone, and Full Name are mandatory fields. This form posts to the same page and sends email. A form can be constructed that posts to another page.<br>
<form runat="server">
<fieldset>
<legend>Information about Yourself</legend>
<table width="600">
<colgroup>
<col width="200">
<col width="150">
<col width="250">
</colgroup>
<tr><td>Organization:</td>
<td><asp:textbox id="Org" runat="server" /></td></tr>
<tr><td>Email:</td>
<td><asp:textbox id="Email" runat="server" /><td>
<asp:requiredfieldvalidator id="EmailRequired" runat="server" controltovalidate="Email">**Enter complete email address</asp:requiredfieldvalidator></td></tr>
<tr><td>Your URL:</td>
<td><asp:textbox id="Email2" runat="server" /></td></tr>
<tr><td>Full Name:</td>
<td><asp:textbox id="FullName" runat="server" /></td>
<td><asp:requiredfieldvalidator id="NameRequired" controltovalidate="FullName" runat="server">**Enter your first and last name</asp:requiredfieldvalidator></td></tr>
<tr><td>Address:</td>
<td><asp:textbox id="Address" runat="server" /></td></tr>
<tr><td>City/Town:</td>
<td><asp:textbox id="City" runat="server" /></td></tr>
<tr><td>State or Country:</td>
<td><asp:textbox id="State" runat="server" /></td></tr>
<tr><td>Postal Code:</td>
<td><asp:textbox id="ZipCode" runat="server" /></td></tr>
</table>
</fieldset>
<fieldset>
<legend>Phone Information</legend>
<table width="600">
<colgroup>
<col width="200">
<col width="400">
</colgroup>
<tr><td>Home Phone:</td>
<td><asp:textbox id="HomePhone" value="(617)-000-0000" runat="server" />
<asp:requiredfieldvalidator id="PhoneRequired" controltovalidate="HomePhone" runat="server">**Please enter your Home Phone</asp:requiredfieldvalidator>
<br><asp:regularexpressionvalidator id="PhoneValidate" runat="server" controltovalidate="HomePhone" validationexpression="^\(?\d{3}\)?(\s|-)\d{3}-\d{4}$">**Phone Number must be in this format (XXX)-XXX-XXXX</asp:regularexpressionvalidator></td></tr>
<tr><td>WorkPhone:</td>
<td><asp:textbox id="WorkPhone" runat="server" /></td></tr>
</table>
</fieldset>
<fieldset>
<legend>Comments:</legend>
<br>
<textarea id="Comments" cols=40 rows=4 runat="server" /></td></tr>
</fieldset>
<asp:button text="Submit for Posting on Same Page, Emails, and Posts to Table" backcolor="navy" font-bold="true" forecolor="white" onclick="OKToNewPage" runat="server"/>
<br><br>

 

<%If Email.Text<>"" AND FullName.Text<>"" AND HomePhone.Text<>"" Then%>
<asp:label id="Header" forecolor="blue" runat="server" /><br><br>
Organization: <asp:label id="LabelOrg" forecolor="blue" runat="server" /><br>
Email: <asp:label id="LabelEmail" forecolor="blue" runat="server" /><br>
URL: <asp:label id="LabelEmail2" forecolor="blue" runat="server" /><br>
Full Name: <asp:label id="LabelName" forecolor="blue" runat="server" /><br>
Address: <asp:label id="LabelAddress" forecolor="blue" runat="server" /><br>
City/State: <asp:label id="LabelCity" forecolor="blue" runat="server" /> <asp:label id="LabelState" forecolor="blue" runat="server" /> <asp:label id="LabelZipCode" forecolor="blue" runat="server" /><br>
Home Phone: <asp:label id="LabelHome" forecolor="blue" runat="server" /><br>
Work Phone: <asp:label id="LabelWork" forecolor="blue" runat="server" /><br>
Comments: <asp:label id="LabelComments" forecolor="blue" runat="server" /><br>
<%End If%>

</form>
<!-- ******** BEGIN ALLWEBMENUS CODE FOR julia2 ******** -->
<!-- ******** END ALLWEBMENUS CODE FOR julia2 ******** -->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR julia ******** -->
<!-- ******** END ALLWEBMENUS CODE FOR julia ******** -->

<!-- DO NOT MOVE! The following AllWebMenus code MUST ALWAYS BE PLACED JUST BEFORE THE /BODY TAG -->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR julialeft ******** -->
<img name='awmMenuPathImg-julialeft' id='awmMenuPathImg-julialeft' src='./awmmenupath.gif' alt=''>
<script type='text/javascript'>var MenuLinkedBy='AllWebMenus [2]', awmBN='432'; awmAltUrl='';</script>
<script src='julialeft.js' language='JavaScript1.2' type='text/javascript'></script>
<script type='text/javascript'>awmBuildMenu();</script>
<!-- ******** END ALLWEBMENUS CODE FOR julialeft ******** -->

</body>
</html>

Code for cookie.aspx

<%@Page Explicit="True" Language="VB" Debug="True"%>
<html>
<head>
<title>ASP.NET Results Form</title>
<STYLE TYPE="text/css">
body { margin-left: .15in; margin-right: .25in; color: black; font-weight: bolder; font-size: 14pt}
h2 {text-align: center; color: white;}
</STYLE>
</head>
<body bgcolor="tan">
<h2>This is your results form. Please print out for your information. Backspace and press the the other submit button for email receipt.</h2><br>
<br><br>
Your form was received by Julia Computer Consulting on <%=Now%> by <a href=mailto:<%=Request.Cookies("Pref")("Email")%>><%=Request.Cookies("Pref")("Email")%></a>
<br><br>
The results are as follows:<br><br>
Organization: <%=Request.Cookies("Pref")("Org")%>
<br>
Email: <a href=mailto:<%=Request.Cookies("Pref")("Email")%>><%=Request.Cookies("Pref")("Email")%></a>
<br>
URL: <a href=<%=Request.Cookies("Pref")("Email2")%>><%=Request.Cookies("Pref")("Email2")%></a>
<br>
Full Name: <%=Request.Cookies("Pref")("Name")%>
<br>
Address: <%=Request.Cookies("Pref")("Address")%> <%=Request.Cookies("Pref")("City")%> <%=Request.Cookies("Pref")("State")%>
<br>
Home Phone: <%=Request.Cookies("Pref")("HomePhone")%>
<br>
Work Phone: <%=Request.Cookies("Pref")("WorkPhone")%>
<br>
Comments: <%=Request.Cookies("Pref")("Comments")%>

</body>
</html>