I have successfully made a couple of contact forms using the methods you outlined in your book and one of them just stopped working when I changed it today.
So you would think that by just undoing the change it would go back to normal? Wrong.
Well obviously it would but I must have made a change that I was not aware of making and I can't spot it anywhere and i'm not getting an error message so I am really confused as to what is causing the problem.
I made 2 changes the first was to the code behind page where I made it grab the users email address and name a write that out in the from bit of the email:
Code:
If Page.IsValid Then
Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt")
Dim mailBody As String = System.IO.File.ReadAllText(fileName)
mailBody = mailBody.Replace("##Name##", txtName.Text)
mailBody = mailBody.Replace("##Email##", txtEmail.Text)
mailBody = mailBody.Replace("##Message##", txtMessage.Text)
Dim myMessage As MailMessage = New MailMessage()
myMessage.Subject = txtSubject.Text
myMessage.Body = mailBody
myMessage.From = New MailAddress(txtEmail.Text, txtName.Text)
myMessage.To.Add(New MailAddress("xxx@xxxxx.x", "xxx"))
Dim mySmtpClient As SmtpClient = New SmtpClient()
mySmtpClient.Send(myMessage)
lblSuccess.Visible = True
contact1.Visible = False
I don't think there are any errors there but just incase.
The second change was in the css file and that was to put ../ infront of the filepath name so it would access from the root as before the image wasn't displaying.
Code:
.pleasewait
{
height: 32px;
width: 32px;
background-image: url(../Images/ajax-loaderB.gif);
background-repeat: no-repeat;
padding-left: 40px;
line-height: 32px;
}
Similarly I don't there is an error there either.
so I will post up the code for the aspx page aswell as I think there is an error in the progress template bit of the update panel as I am not getting an error message directly but when I put custom errors on it takes me to my custom error page so I find it odd that it isn't displaying any error message.
Code:
<!--**************Contact Form*****************-->
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div id="contact1" runat="server">
<asp:label runat="server" ID="lblName" Text="Name:" />
<asp:TextBox id="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please enter a name." ControlToValidate="txtName"
CssClass="error">*</asp:RequiredFieldValidator><br />
<asp:Label runat="server" ID="lblEmail" Text="Email:" />
<asp:TextBox runat="server" ID="txtEmail" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Please enter an email address." ControlToValidate="txtEmail" CssClass="error">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Please enter a valid email address, eg: you@yourprovider.com." ControlToValidate="txtEmail" CssClass="error" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator><br />
<asp:Label runat="server" id="lblSubject" text="Subject:"></asp:Label>
<asp:TextBox runat="server" id="txtSubject" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Please enter a subject" ControlToValidate="txtSubject" CssClass="error">*</asp:RequiredFieldValidator><br />
<asp:Label runat="server" ID="lblMessage" Text="Message:" />
<asp:TextBox runat="server" ID="txtMessage" TextMode="MultiLine" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please enter a message" ControlToValidate="txtMessage" CssClass="error">*</asp:RequiredFieldValidator><br />
<asp:Button runat="server" ID="btnSubmit" Text="Submit Form!" CssClass="submit" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Please correct the following errors:" />
<asp:UpdateProgress runat="server">
<progresstemplate>
<div class="pleasewait">
<p>Please Wait...</p>
</div>
</progresstemplate>
</asp:UpdateProgress>
</div>
<asp:Label ID="lblSuccess" runat="server" Visible="false" class="success">Congratulations! Your message has been sent successfully.</asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Any help would be good thanks or a point in the right direction.