Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2009, 05:06 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default My contact form stopped working..again.

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.
 
Old March 18th, 2009, 09:52 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hi Will.

"Not working" can mean alot of things to different people. What is the page doing (or not doing)? Is it throwning an exception?

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old March 19th, 2009, 05:23 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Ok sorry let me try to be a little more specific.

Basically you input the required information and then click the button at which point a progresstemplate should display a little animkated saying please wait and then the contact form disapears and a label displays saying success etc.

The problem occurs when the button is clicked. Nothing seems to happen the information is still visible in the contact form it's almost like the button hasn't been clicked in terms of the state of the contact form.

No exception is thrown but when I turn my custom error page on it automatically goes to that but when I take it off it doesn't display an error.

So I either think there must be an error in the button click event handler or the progresstemplate as that is the next part of the contact form stage that doesn't actually work.

I hope this helps you better and thanks for looking over my problem.
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old March 19th, 2009, 05:49 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Try removing the <UpdatePanel> so you can see the real error....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 19th, 2009, 06:09 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Is that why I am not getting an error? Ok so now some progress can happen.

The error I get is:

Syntax error in parameters or arguments. The server response was: Your domain does not seem to be valid. Could not find MX record for your domain.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: Syntax error in parameters or arguments. The server response was: Your domain does not seem to be valid. Could not find MX record for your domain.

Source Error:

Line 22:
Line 23: Dim mySmtpClient As SmtpClient = New SmtpClient()
Line 24: mySmtpClient.Send(myMessage)
Line 25:
Line 26:
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old March 19th, 2009, 10:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, the server side exception is swallowed / hidden by the client side AJAX panel.

The error suggest that your From or To addresses are not valid. Maybe you have an invalid From address in web.config?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 21st, 2009, 09:07 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

My config stuff is fine... as far as I can tell. In that I haven't touched it at all and it was working before.

This bit of code here should work shouldn't it?
Code:
 myMessage.From = New MailAddress(txtEmail.Text, txtName.Text)
Where txtEmail is the email textbox and txtName is the name textbox.
 
Old March 21st, 2009, 09:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, that looks fine. But could it be that the address entered in that text box is invalid? From addresses need to be valid as well.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 21st, 2009, 09:30 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

yeah when I test it I have got a validator that catches it in the update panel if it isn't valid or not.

The code in the config file is good, the code behind is good and the .aspx page is good...

I must have made a typo somewhere unless you can think of anything else?
 
Old March 21st, 2009, 09:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's not just about being valid; it's also about being real and existing e-mail address.

This:

imar@jsyefcbgrewufcgrfeu.nl

Is a valid e-mail address. This means the validator will let it pass. However, the domain doesn't exist, so I'll get an error when I use it as a From address....

Take another look at your error:

Quote:
Syntax error in parameters or arguments. The server response was: Your domain does not seem to be valid. Could not find MX record for your domain.
This indicates that the code works fine, but that the sending mail server rejects the message because it cannot find an MX record for the domain name used in the From or To addresses.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Intellisence stopped working beddowsm Visual Studio 2008 3 September 5th, 2008 12:32 PM
Logins stopped working after adding to web.config troyb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 September 2nd, 2008 03:34 PM
date function stopped working in report Loralee Access 6 December 8th, 2005 07:11 PM
Help... Smtp.Mail.Send stopped working funtent General .NET 1 October 27th, 2004 07:26 AM
Intellisense stopped working in InterDev 6 riga1966 Classic ASP Professional 3 June 1st, 2004 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.