Hello sir,
I am working on contact.aspx page. I am using update panel with it to show the waiting image. It is working fine. But when I use the file attachment to it then file does not get sent with the message, but if I remove the update panel then it works fine.
my code for the markup (ContactForm.ascx) is
Code:
<asp:UpdatePanel ID="UpdatePanel1" runat ="server" >
<ContentTemplate >
<table class="style1" runat="server" id="FormTable">
same as in book. The extra field is file upload...
<td align="right" class="style16">
Attach Your File ( If Any ):</td>
<td class="style5">
<asp:FileUpload ID="FileUpload1" runat="server" Font-Bold="True"
Font-Italic="True" ForeColor="#39561D" />
</td>
<td class="style15">
</td>
</tr>
<tr>
<td class="style3" align="right">
</td>
<td class="style2">
<asp:Button ID="btnSend" runat="server" Text="Submit Feedback" Font-Bold="True" Font-Italic="True"
ForeColor="#39561D" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style7" colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Please Correct The Following Errors Before You Press The Button"
Height="156px" Font-Bold="True" Font-Italic="True" ShowMessageBox="True" />
</td>
</tr>
</table>
<asp:Label ID="lblMessage" runat="server" Text="Message Sent" Visible="false"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID ="UpdatePanel1">
<ProgressTemplate >
<div class="PleaseWait">Please Wait...</div>
</ProgressTemplate>
</asp:UpdateProgress>
And the code behind file is
Code:
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSend.Click
If Page.IsValid Then
Dim fileName As String = Server.MapPath("~/App_Data/FeedbackForm.txt")
Dim mailBody As String = System.IO.File.ReadAllText(fileName)
mailBody = mailBody.Replace("##Name##", txtName.Text)
mailBody = mailBody.Replace("##Email##", txtEmailAddress.Text)
mailBody = mailBody.Replace("##HomePhone##", txtPhoneHome.Text)
mailBody = mailBody.Replace("##BusinessPhone##", txtPhoneBusiness.Text)
mailBody = mailBody.Replace("##Comments##", txtComments.Text)
Dim myMessage As New MailMessage()
myMessage.Subject = "Feedback From Web Site"
myMessage.Body = mailBody
myMessage.From = New MailAddress("[email protected]", "Name")
myMessage.To.Add(New MailAddress("[email protected]", "Name"))
If FileUpload1.HasFile Then
Dim fileName1 As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim myAttachment As New Attachment(FileUpload1.FileContent, fileName1)
myMessage.Attachments.Add(myAttachment)
End If
Dim mySmtpClient As New SmtpClient()
Try
mySmtpClient.EnableSsl = True
mySmtpClient.Send(myMessage)
Catch ex As Exception
'ex.Message.ToString();
lblMessage.Text = "Sorry,An Error Occurred While Sending Your Message. Please Try Again."
End Try
lblMessage.Visible = True
FormTable.Visible = False
End If
End Sub
Any help is most appreciated.
Thank you.