tags:

views:

126

answers:

6

This is my first time creating a from in ASP.NET I am following a tutorial here

This is the error:

Line 23:     output += "<p>Groupe: " + Request.Form["c_Groupe"].ToString() + ".</p>";
Line 24:     output += "<p>Numéro de téléphone: " + Request.Form["c_Tel"].ToString() + ".</p>";
Line 25:     output += "<p>J'aimerais être bénévole pour: " + Request.Form["La bibliothèque","Aide en classe","Aide pour les dîners pizza","Aide aux devoirs après l’école","Aménagement paysager (fleurs, arbustes à tailler…)","Photo scolaire","Accompagner les élèves lors des sorties", "Venir parler de votre métier dans une classe ou monter un atelier "].ToString() + ".</p>";
Line 26:     output += "<p>Autres: " + Request.Form["c_Autre"].ToString() + ".</p>";
Line 27:
+1  A: 

update your web.config file to show errors

<customErrors mode="Off" />

Removing your header probably isn't the best solution, so that makes me think the error is in your contact-form.aspx.cs page. The REAL exception should display once you add the above to your web.config.

hunter
created a web.config and updated my post
kwek-kwek
try running your app in Debug Mode instead. It still seems like you didn't update the web.config customErrors mode. To Debug hit the Green arrow in the toolbar of Visual Studio.
hunter
updated the error
kwek-kwek
+2  A: 

Put

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

In your web.config so we can see the error but It's probably something to do with the

CodeFile="contact-form.aspx.cs" Inherits="_Emailer"

Bit. Either the contact-form.aspx.cs file is missing or the partial class in the code-behind has a different name to _Emailer.

Ah, It looks like you have created a web application project. You need to either build the project first and then ftp all the files to your web server including the bin folder or an easier alternative is to use Visual Studios publish option which will prompt you for your ftp details and do the rest for you

Nick Allen - Tungle139
created a web.config and updated my post
kwek-kwek
updated the error
kwek-kwek
Hey Nick - http://www.kayak.com/flippy/Cqi9_W (sorry - bit of colleague rivalry!)
adam
+1  A: 

I think your label which sits outside the form tag should be inside it see below.

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<asp:label id="lblOutcome" runat="server" />
Michael Ciba
+1 - that seems the likely candidate.
CAbbott
created a web.config and updated my post
kwek-kwek
+1  A: 

Aren't you missing the runat="server" in the form declaration?

<form id="form1" runat="server" enctype="multipart/form-data" method="post">

Also, you might be getting errors if the Namespace isn't correct, I've seen it happen, for example, after someone renamed the solution and forgot to change the namespace in all the files.

Otherwise, like the others have told you, seeing the actual error would help a lot

Johann J.
created a web.config and updated my post
kwek-kwek
A: 

It looks like this sample was build using the .NET framework 1.1, is that the framework version you have set for this application on IIS? You might want to check your IIS settings to make sure the framework version is set correctly.

Hope this helps!

Ricardo
CodeFile is used in asp.net framework 2.0. In framework 1.1 it was src. I think he just needs to switch the application framework on the IIS setting to v2.0 and should be good to go.
clyc
@clyc - you are correct, thanks for the clarification.
Ricardo
+1  A: 

are you coding this for asp.net 1.1 or asp.net 2.0?

The syntax looks like it is for asp.net 2.0 but your web server is running in 1.1 mode.

for asp.net 1.1 the following line:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="contact-form.aspx.cs" Inherits="_Emailer" %>

should be:

<%@ Language="C#" Inherits="_Emailer" src="contact-form.aspx.cs" %>

If you have access to the web sever, just switch the .net Framework version to v2.0 and you should be good to go without having to make any modifications. If not let me know.


I rewrote your codebehind for asp.net 1.1.... I'm doing this from memory so there might be mistakes..

using System;
using System.Text;
using System.Web.Mail;

public class _Emailer : System.Web.UI.Page 
{
 protected void Page_Load(object sender, System.EventArgs e)
 {
  if(IsPostBack)
  {
   try
   {

    string output = "";

    MailMessage mail = new MailMessage();
    string hostAddress = "aaa.bbb.ccc.ddd";

    string message = Request.Form["c_Message"].ToString();
    message = message.Replace(Environment.NewLine, "<br />");

    StringBuilder sb = new StringBuilder();
    sb.AppendFormat("<p>Nom du Parent: {0}.</p>", Request.Form["c_Name"].ToString());
    sb.AppendFormat("<p>Nom de votre enfant: {0}.</p>",  Request.Form["c_Enfant"].ToString());
    sb.AppendFormat("<p>Groupe: {0}.</p>", Request.Form["c_Groupe"].ToString());
    sb.AppendFormat("<p>Numéro de téléphone: {0}.</p>", Request.Form["c_Tel"].ToString());
    sb.AppendFormat("<p>J'aimerais être bénévole pour: {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}.</p>",
        Request.Form["La bibliothèque"].ToString(),
        Request.Form["Aide en classe"].ToString(),
        Request.Form["Aide pour les dîners pizza"].ToString(),
        Request.Form["Aide aux devoirs après l’école"].ToString(),
        Request.Form["Aménagement paysager (fleurs, arbustes à tailler…)"].ToString(),
        Request.Form["Photo scolaire"].ToString(),
        Request.Form["Accompagner les élèves lors des sorties"].ToString(),
        Request.Form["Venir parler de votre m&eacute;tier dans une classe ou monter un atelier"].ToString()
    );  
    sb.AppendFormat("<p>Autres: {0}.</p>", Request.Form["c_Autre"].ToString());

    mail.Subject = "New e-mail.";
    mail.From = "[email protected]";
    mail.To = "[email protected]";
    mail.Body = sb.ToString();

    mail.BodyFormat = MailFormat.Html

    SmtpMail.SmtpServer = hostAddress;
    SmtpMail.Send(mail);

    lblOutCome.Text = "E-mail sent successfully.";
   }

   catch (Exception err)
   {
    lblOutCome.Text = "There was an exception whilst sending the e-mail: " + err.ToString() + ".";
   }
  }
 }
}
clyc
I've change it but there is a news error Line 4: public partial class _Emailer : System.Web.UI.Page
kwek-kwek
Get rid of the word partial ( this was added for .net 2.0).It should look like this:public class _Emailer: System.Web.UI.Page
clyc
Do you have access to the IIS server kewk-kwek?
clyc
I don't have access
kwek-kwek
took off the "partial" but then a new error Line 2: using System.Net.Mail;
kwek-kwek
yea System.Net.Mail is part of the .net 2.0 framework. Where are you hosting this example? No IIS manager?Look at this link to learn how to send mail in 1.1 framework if you can't change it to 2.0.http://www.velocityreviews.com/forums/t103795-sending-email-from-asp-net-1-1-a.html
clyc
I am hosting this where it's located right now.... The reason why I have no acces on the IIS is that they are on a shared hosting. I look at the link you sent me an honestly I have no clue what to do.. hehe I am not a programmer, I am more a front end developer. This is my first time working with ASP.net Kindly please explain me which or how to change stuff...
kwek-kwek
check my edited post. I rewrote the codebehind for you.
clyc
thank you so much for this help but now I am having an error with this Line 25: output += "<p>J'aimerais être bénévole pour: " + Request.Form["La bibliothèque","Aide en classe","Aide pour les dîners pizza","Aide aux devoirs après l’école","Aménagement paysager (fleurs, arbustes à tailler…)","Photo scolaire","Accompagner les élèves lors des sorties", "Venir parler de votre métier dans une classe ou monter un atelier"].ToString() + ".</p>";
kwek-kwek
I have updated my post
kwek-kwek
I don't see the error message. I need the stacktrace of it. can you post a link to that error like before so that I can check it out?
clyc
Ok. I see what your problem is... You cannot do what you are doing on line 25. I'm assuming that everything between Request.Form and the .ToString() are variables in your form. You would have to append each one individually like: Request.Form["La bibliothèque"].ToString() + Request.Form["Aide en classe"].ToString + whatever else you have.
clyc
modified the example to show you what I meant.Also changed the code to use the StringBuilder class. This is a more efficient way of concatenating strings and also improves the readability of the code.
clyc
Thanks for the response new error Line 40: mail.From = new MailAddress("[email protected]");
kwek-kwek
updated code above
clyc