Crazy question about emailing form results

Topics: ASP.NET 2.0
Dec 16, 2010 at 7:45 PM

I am using BE 2.0 RC, SQL-CE and ASP.Net 4.0.

I have several forms on my website that send results to several email recipients.  I am currently using a program called AutoEmail to send the results, the issue I am having is that it conflicts with the Newsletter option in BE, if I try to use the Newsletter option then AutoEmail quits sending form results.  

Is there some way I can use the same method that BE uses for the contact form to send my other forms in the website so I may use the Newsletter option and keep sending my form results?  

Or can someone point me to a tutorial that would teach me how to send form results using ASP.Net?  

Thanks for your help and suggestions.

Coordinator
Dec 17, 2010 at 3:17 AM

Maybe somebody will jump in, but what are "form results" ?   When and how are they sent out?  Is it automatic?  Or does a person click a button?  Are you sending them, or does the person initiate the sending?

The newsletter widget automatically sends emails when a new post is created -- that's the trigger.  What's the trigger for these "form results" ?

You also mentioned the "contact form".  I wasn't sure what connection there is between the contact form and the newsletter widget.

Sorry, lots of questions ... just am not clear on what the process is here.

Dec 17, 2010 at 3:47 AM

This is the form:

http://www.sahcinfo.org/hikingforms/hikeschedule1.aspx

The form results are sent by a program called AutoEmail when the form is submitted by the submit button,  it auto formats everything and does the work when the form is submitted.

If I enable the Newsletter then AutoEmail quits working.

I mentioned the Contact form because it sends emails it's results when submitted.

Here is the form in code view.


<%@ Page Title="" Language="C#"  AutoEventWireup="true" MasterPageFile="" CodeFile="hikeschedule1.aspx.cs" Inherits="hikeschedule1" %>

<%@ Import Namespace="BlogEngine.Core" %>

<%@ Register
    Assembly="AjaxControlToolkit"
    Namespace="AjaxControlToolkit"
    TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="By360Impact.AutoEmail" Namespace="By360Impact.AutoEmail" TagPrefix="cc1" %>
<script runat="server">  
   
    
    

    protected void Button1_Click(object sender, EventArgs e)
    {
        AutoEmail1.Initiate();
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="cphBody" Runat="Server">
<asp:ScriptManager runat="server"></asp:ScriptManager>

  <div ID="contact">
    <h1>Schedule A Hike</h1>
    </div>

 
<table style="width: 594px">
                            <tr>
                                <td style="width: 182px; height: 21px">
                                    Hike Title</td>
                                <td style="width: 31px; height: 21px">
                                    <asp:TextBox ID="Hike_title" runat="server" MaxLength="40" Width="197px"></asp:TextBox>
                                </td>
                                <td>
                                    Please limit to 40 characters&nbsp;</td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 21px">
                                    Rating</td>
                                <td style="width: 31px; height: 21px">
                                    <asp:TextBox ID="Rating" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 157px; height: 21px">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Hike_title"
                                        ErrorMessage="*" SetFocusOnError="True">Hike title required</asp:RequiredFieldValidator></td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 21px">
                                    Miles</td>
                                <td style="width: 31px; height: 21px">
                                    <asp:TextBox ID="Miles" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 157px; height: 21px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Climb</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Climb" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Hike Type</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Hike_type" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                    Trail,route,road,bushwhack,carcamp,backpack,etc.</td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Map</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Map" runat="server"></asp:TextBox>
                                </td>
                                <td>
                                    </td>
                            </tr>
                            <tr>
                                <td style="width: 182px" valign="top">
                                    Day/Date</td>
                                <td style="width: 31px" valign="top">
                                    <asp:TextBox ID="Date" runat="server"></asp:TextBox>
                           <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="dddd, MM/dd/yy"
                                        TargetControlID="Date">
                           </ajaxToolkit:CalendarExtender>
                                </td>
                                <td>
                                    Please do not type date, place cursor in Day/Date field, choose date from calendar and the correct day is 
                                    automatically included.
                                    Javascript must be enabled in your browser.</td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 22px" valign="top">
                                    &nbsp;</td>
                                <td style="width: 31px">
                                    &nbsp;</td>
                                <td>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Date"
                                        ErrorMessage="*" SetFocusOnError="True">Hike date required</asp:RequiredFieldValidator></td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 21px">
                                    Meeting Place</td>
                                <td style="width: 31px; height: 21px">
                                    <asp:DropDownList ID="Meeting_Place" runat="server" Width="187px">
                                        <asp:ListItem>CAT</asp:ListItem>
                                        <asp:ListItem Selected="True">PAW</asp:ListItem>
                                        <asp:ListItem>Oracle &amp; Magee</asp:ListItem>
                                        <asp:ListItem>Park &amp; Ride I-10</asp:ListItem>
                                        <asp:ListItem>SC-VC</asp:ListItem>
                                        <asp:ListItem>Fry's</asp:ListItem>
                                        <asp:ListItem>Sunrise Village</asp:ListItem>
                                        <asp:ListItem>Food City</asp:ListItem>
                                        <asp:ListItem>TV-SAB</asp:ListItem>
                                        <asp:ListItem>Wilmot Plaza</asp:ListItem>
                                        <asp:ListItem>Chevron I-10 East</asp:ListItem>
                                        <asp:ListItem>Other (see hike description)</asp:ListItem>
                                        <asp:ListItem>Contact Guide</asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td style="width: 107px; height: 21px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Time</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Time" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 28px;">
                                    Drive Miles</td>
                                <td style="width: 31px; height: 28px;">
                                    <asp:TextBox ID="Drive_miles" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px; height: 28px;">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 21px">
                                    Area</td>
                                <td style="width: 31px; height: 21px">
                                    <asp:TextBox ID="Area" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px; height: 21px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Guide 1</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Guide_1" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                        ControlToValidate="Guide_1" ErrorMessage="*" Height="21px" 
                                        SetFocusOnError="True" Width="176px">Guide name required</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Phone 1</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Phone_1" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Email 1</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Email_1" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px; height: 16px;">
                                    Guide 2</td>
                                <td style="width: 31px; height: 16px;">
                                    <asp:TextBox ID="Guide_2" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px; height: 16px;">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Phone 2</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Phone_2" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px">
                                    Email 2</td>
                                <td style="width: 31px">
                                    <asp:TextBox ID="Email_2" runat="server"></asp:TextBox>
                                </td>
                                <td style="width: 107px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px" valign="top">
                                    Hike Description</td>
                                <td colspan="2">
                                    <asp:TextBox ID="Hike_description" runat="server" TextMode="MultiLine" Width="360px" Rows="8"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 182px" valign="top">
                                    &nbsp;</td>
                                <td align="right" colspan="2">
                                   
                                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit hike" /></td>
                            </tr>
                        </table>
                   
<cc1:AutoEmail ID="AutoEmail1" runat="server" AutoInitiate="False" MailBCCAddr="<#Email_2#>"
                                MailCCAddr="president@sahcinfo.org"
                                MailFromAddr="contact@sahcinfo.org" MailServer="mail.sahcinfo.org" MailSubject="<#hike_title#>"
                                
                            MailToAddr="chief_guide@sahcinfo.org,sahcchief2006@yahoo.com,webmaster@sahcinfo.org,midweek@sahcinfo.org,beditor@sahcinfo.org,<#Email_1#>" 
                            RedirectURL="http://blogengine.sahcinfo.org/page/Form-confirmation.aspx"
                            SMTPPass="hiker1" SMTPUser="contact@sahcinfo.org" /> 
                            
                            <p> Please submit hike once and wait for confirmation.
                    If you receive confirmation and your info is correct, please do not submit the form
                    twice for the same hike. If you feel there is a problem when submitting your hike
                    please contact the webmaster. Thank you</p>
                <p>
                    Keep write up as short as practical (about 6 lines or less printed in bulletin).&nbsp;
                    Six lines will contain between 74 and 93 words.<br />
                    Please use the "Hike Rating" field for degree of difficulty only.
                </p>
                <p>
                    This form will be emailed to the Bulletin Editor. Hikes submitted will be reviewed
                    by the Chief Guide or Midweek Coordinator as appropriate and then posted on the
                    Scheduled Hikes page which will indicate approval of your hike.</p>

  
</asp:Content>

Coordinator
Dec 17, 2010 at 4:15 AM

Thanks, this helps a lot.  So if you remove the Newsletter widget, then this form works.  With the Newsletter widget, the form doesn't work ... right ?

When the prior version of BE (1.6), did you successfully have this form and the Newsletter widget on the page at the same time?  Just wondering if this is a new problem since BE 2.0.

If you can get the Newsletter widget and this form to co-exist, that's the goal, right ?

Dec 17, 2010 at 12:48 PM
Edited Dec 17, 2010 at 1:02 PM

Yes my immediate goal is too have both the emailing of my forms and the Newsletter feature co-exist, it did not work with 1.6 either.

My long term goal is to do away with AutoEmail and learn how to setup the forms to work with System.Net.Mail, it would be nice not to be tied to AutoEmail.  I have about 5 forms as complex as the one that I sent you and that would be a lot of coding, but I think I should learn how to set it up.

Dec 18, 2010 at 9:25 AM

 

Yes my immediate goal is too have both the emailing of my forms and the Newsletter feature co-exist, it did not work with 1.6 either.

My long term goal is to do away with AutoEmail and learn how to setup the forms to work with System.Net.Mail, it would be nice not to be tied to AutoEmail.  I have about 5 forms as complex as the one that I sent you and that would be a lot of coding, but I think I should learn how to set it up.

Coordinator
Dec 18, 2010 at 7:33 PM

Sending an email with System.Net.Mail is easy.  The time consuming part is building up the email body contents to include all the details entered into the form.

I took a quick look, but am not sure where the conflict is with the Newsletter widget.

Dec 18, 2010 at 8:06 PM

Thanks for looking Ben, I really need to try to learn and use System.Net.Mail for my hiking forms so I can use the Newlsetter widget.

Dec 19, 2010 at 12:44 PM

Ben, to use System.Net.Mail in BE 2.0 do I need to modify my web.config with these settings?  Thanks

 <system.net>

    <mailSettings>

      <smtp from="test@foo.com">

        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />

      </smtp>

    </mailSettings>

  </system.net>

 

 

Coordinator
Dec 19, 2010 at 8:47 PM

You can do that ... but since you're doing this from BE (I believe), you can use the existing mail sending capabilities in BE, which use the email settings you have on the Settings tab in the control panel.

BE has a function Utils.SendMailMessage() that sends an email and uses the email settings defined in the control panel.  An example of this is in contact.aspx.cs.

Here's something to get you started.  Using the hikeschedule1.aspx page you posted above, do this:

1.  At the top of hikeschedule1.aspx, add these 2 lines:

<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Text" %>

2.  In hikeschedule1.aspx, you have a <script> tag with a Button1_Click handler.  Replace that with this:

<script runat="server">  

    private string CreateRow(string label, string value)
    {
        return string.Format(
            "<tr><td><b>{0}</b></td><td>{1}</td></tr>",
            HttpUtility.HtmlEncode(label),
            HttpUtility.HtmlEncode(value));
    }    

    protected void Button1_Click(object sender, EventArgs e)
    {
        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(BlogSettings.Instance.Email);

            mail.To.Add("chief_guide@sahcinfo.org");
            mail.To.Add("sahcchief2006@yahoo.com");
            mail.To.Add("webmaster@sahcinfo.org");
            mail.To.Add("midweek@sahcinfo.org");
            mail.To.Add("beditor@sahcinfo.org");

            mail.Subject = Hike_title.Text;

            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"1\" cellpadding=\"5\">");

            sb.Append(CreateRow("Hike Title", Hike_title.Text));
            sb.Append(CreateRow("Rating", Rating.Text));
            sb.Append(CreateRow("Miles", Miles.Text));
            
            sb.Append("</table>");

            mail.IsBodyHtml = true;
            mail.Body = sb.ToString();

            string errorMessage = Utils.SendMailMessage(mail);
            if (string.IsNullOrEmpty(errorMessage))
            {
                // success
                Response.Redirect("http://blogengine.sahcinfo.org/page/Form-confirmation.aspx");
            }
            else
            {
                Response.Write("An error occurred sending the email.  Error: " + errorMessage);
            }
        }
        
    }
</script>

When the "submit hike" button is clicked, it will create a MailMessage.  The "from" address will come from the email settings you have in the control panel.  5 people are added as recipients, a Subject is set.  And then it builds up the body of the email.  I created a helper function called "CreateRow" that creates an HTML table row and includes the "label" and "value".  It only does this for the first 3 fields on the page.  To complete this, you would want to add more sb.Append(CreateRow(...)) statements for the remaining fields.  Then at the end, it uses Utils.SendMailMessage() to send the MailMessage.  If it's successful, it will do the redirect.  Otherwise, it'll output an error message to the top of the page.

You could of course directly use System.Net.Mail instead of calling Utils.SendMailMessage().  But SendMailMessage() helps to take remove some of the extra code you would have to write yourself.

Dec 19, 2010 at 9:00 PM

Thank you Ben, this is a great tool for me to learn this, I will work on this for the remaining fields.

Then it's onward to my other forms.

What would the code be for cc and bcc email addresses.

Also this should all go on the aspx page and not the .cs page, correct?

Coordinator
Dec 19, 2010 at 9:02 PM

For CC and BCC, here is an example:

mail.CC.Add("someone@example.com");
mail.Bcc.Add("someone@example.com");

The code could be put into the .aspx.cs file instead of the .aspx page -- that's what I prefer.  But it also works in the .aspx page within a <script runat="server"> tag.  I did it this way since you already had a Button1_Click handler in the .aspx page.

Dec 19, 2010 at 9:13 PM
Edited Dec 19, 2010 at 9:53 PM

Thank you, 1 more question, will

sb.Append(CreateRow("Hike Title", Hike_title.Text));
work for the DropDownList also?

Also will it work for the multiline textbox?

Edit:

I answered my own questions Ben, thanks again for all your help, I published my hiking form and successfully submitted all the info, it looks better then the original.  Onward to my other hiking forms.

 

Dec 19, 2010 at 11:08 PM
Edited Dec 19, 2010 at 11:10 PM

Ben, I am hung up on trying to add the email address in the form field email_1 to the email recipient list, is this possible?  Sometimes this field will be blank.

I tried this but got an error.

 

  mail.To.Add("email_1");

Coordinator
Dec 19, 2010 at 11:14 PM

You can use this, which checks to see if a valid email address has been entered into Email_1, and if so, adds it:

if (Utils.IsEmailValid(Email_1.Text))
	mail.To.Add(Email_1.Text.Trim());

Dec 19, 2010 at 11:17 PM

Is there any special place I have to put it, like right after the email addresses?

Coordinator
Dec 19, 2010 at 11:19 PM

At the same place where you're adding the other email addresses will work.  Like ....

...........
mail.To.Add("midweek@sahcinfo.org");
mail.To.Add("beditor@sahcinfo.org");

if (Utils.IsEmailValid(Email_1.Text))
	mail.To.Add(Email_1.Text.Trim());

Dec 19, 2010 at 11:20 PM

Thank you, it works great, 3 forms down and 3 to go.

Dec 20, 2010 at 12:19 AM
Edited Dec 20, 2010 at 12:20 AM

I am back pestering you again Ben, thank your for your help and time.

If I wish to send a form from a different email address would I use this:

message.From = new MailAddress("contact1@sahcinfo.org");

in place of this:

mail.From = new MailAddress(BlogSettings.Instance.Email);

I have one form I need to send from another address instead of the one setup in BE.

How would I put in the password, smpt etc.

Coordinator
Dec 20, 2010 at 4:46 AM
Edited Dec 20, 2010 at 4:50 AM

You can change the From address like you are doing.  That'll be okay.

If the SMTP server and Username/Password you specify in the email settings in the control panel are still valid, then there's nothing extra to do.

If you need to specify a different SMTP server, Username and/or Password, you could either temporarily change the SMTP Server, Username and Password while you are sending the email (i.e. just for 1 second), otherwise, you would need to probably copy the mail sending code from Utils.SendMailMessage(), and modify it to use a custom SMTP Server, Username, and Password instead of the ones saved in the control panel settings.  You would then call this new code, instead of calling Utils.SendMailMessage().

EDIT:  If the purpose of changing the From address is so if a person replies, the reply goes to contact1@sahcinfo.org, you can accomplish that by not changing the From address, but adding a ReplyTo address.  Like this:

mail.ReplyTo = new MailAddress("contact1@sahcinfo.org");
If you do this, and the email recipient clicks "Reply" in their email program, the reply will go to this ReplyTo address.  Not sure if this is the reason you are looking to change the From address, but just thought I'd bring it up.

Dec 20, 2010 at 5:45 AM

Thanks Ben for the info.  I just need to send one of my forms from a different email address, the other parameters remain the same as the settings in the control panel.

Thank you for all your help, my website is really working nice, I love the new control panel, adding a new post is great and SQL_CE is faster adding new users then Vista DB was.

I am looking forward to the final release so I can update the code and solve some minor issues.

Dec 22, 2010 at 12:10 AM

Hi Ben,

Is there a way to make the results of this form take up less room,  it seem the Membership Secretary is complaining she can't fit it all on 1 printed page.  Can we make the table smaller or something like that.  Thank you.

 

<script runat="server">  

    private string CreateRow(string label, string value)
    {
        return string.Format(
            "<tr><td><b>{0}</b></td><td>{1}</td></tr>",
            HttpUtility.HtmlEncode(label),
            HttpUtility.HtmlEncode(value));
    }    

    protected void Button2_Click(object sender, EventArgs e)
    {
        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(BlogSettings.Instance.Email);

            mail.To.Add("treasurer@sahcinfo.org");
            mail.To.Add("membership@sahcinfo.org");
            mail.To.Add("beditor@sahcinfo.org");
            mail.To.Add("eHikes@sahcinfo.org");
            mail.To.Add("president@sahcinfo.org");
            mail.To.Add("webmaster@sahcinfo.org");

            

            mail.Subject = "Online SAHC Membership Application";

            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"1\" cellpadding=\"5\">");

            sb.Append(CreateRow("Primary A Last Name", Primary_last_name.Text));
            sb.Append(CreateRow("Primary A First Name", Primary_first_name.Text));
            sb.Append(CreateRow("Primary A Under 18", Primary_under_18.Text));
            sb.Append(CreateRow("Primary A Number", Primary_A_number.Text));
            sb.Append(CreateRow("Bulletin Format", Bulletin_Format.Text));
            sb.Append(CreateRow("Additional B Last Name", B_last_name.Text));
            sb.Append(CreateRow("Additional B First Name", B_first_name.Text));
            sb.Append(CreateRow("Additional B Under 18", B_under_18.Text));
            sb.Append(CreateRow("Additional B Number", B_number.Text));
            sb.Append(CreateRow("Additional C Last Name", C_last_name.Text));
            sb.Append(CreateRow("Additional C First Name", C_first_name.Text));
            sb.Append(CreateRow("Additional C Under 18", C_under_18.Text));
            sb.Append(CreateRow("Additional C Number", C_number.Text));
            sb.Append(CreateRow("Additional D Last Name", D_last_name.Text));
            sb.Append(CreateRow("Additional D First Name", D_first_name.Text));
            sb.Append(CreateRow("Additional D Under 18", D_under_18.Text));
            sb.Append(CreateRow("Additional D Number", D_number.Text));
            sb.Append(CreateRow("Donation", Donation.Text));
            sb.Append(CreateRow("Total Dues", Total.Text));
            sb.Append(CreateRow("Address", Address.Text));
            sb.Append(CreateRow("Apartment", Other.Text));
            sb.Append(CreateRow("City", City.Text));
            sb.Append(CreateRow("State", State.Text));
            sb.Append(CreateRow("Zip", Zip.Text));
            sb.Append(CreateRow("Phone", Phone.Text));
            sb.Append(CreateRow("Email",Email.Text));
            sb.Append(CreateRow("Address Listed", Address_listed.Text));
            sb.Append(CreateRow("Phone Listed", phone_listed.Text));
            sb.Append(CreateRow("Email Listed", email_listed.Text));
            sb.Append(CreateRow("Referred by", Referred_by.Text));
            sb.Append(CreateRow("Explain other", Explain_other.Text));
            sb.Append(CreateRow("Assumption", Assumption.Text));
            sb.Append(CreateRow("Date", Date.Text));
            sb.Append(CreateRow("Payment made by", Payment_made_by.Text));
               
                      
                      
                      
                       
            sb.Append("</table>");

            mail.IsBodyHtml = true;
            mail.Body = sb.ToString();

            string errorMessage = Utils.SendMailMessage(mail);
            if (string.IsNullOrEmpty(errorMessage))
            {
                // success
                Response.Redirect("http://sahcinfo.org/membership_complete.htm");
            }
            else
            {
                Response.Write("An error occurred sending the email.  Error: " + errorMessage);
            }
        }
        
    }
</script>

Coordinator
Dec 22, 2010 at 3:50 AM

Three ways come to mind.

The simple one would be to reduce the padding of the cells.  This will work if the form is just barely going over one page.  The change would be to cellpadding.  Currently, it's at 5.  You could change it to 2 or 3, or even 1.

sb.Append("<table border=\"1\" cellpadding=\"2\">");

If it's still going over one page, then a 2nd option would be to format it so there are more columns.  So rather than a 2 column layout, it could be a 4 column layout.

The 3rd option would be to combine certain values into a single row.  For example, instead of having "Primary A Last Name" and "Primary A First Name" each on their own row, it could be combined into "Primary A Name" which would show First Name, space, Last Name.  Another example is where you have City, State and Zip as 3 separate rows.  They could be combined into a single row.

Probably the 3rd option is simpler to implement than the 2nd option.  And option 3 could be done for all these other names too -- combining First and Last name into a single row, instead of 2 rows for each person.  Here's a code sample combining some of the data into single rows.

sb.Append(CreateRow("Primary A Name",
	string.Format("{0} {1}", Primary_first_name.Text, Primary_last_name.Text)));

sb.Append(CreateRow("City/State/Zip",
	string.Format("{0}, {1} {2}", City.Text, StateBag.Text, Zip.Text)));

 

Dec 22, 2010 at 4:55 AM

Thanks Ben, this solved the issue for me, I combined  the names for the Primary,  B, C, and D, City, State, Zip, and several other fields as well and also reduced the padding a bit.  This has been a great learning experience for me.  Thank you so much.

Dec 25, 2010 at 6:07 PM

Ben,

Is there some simple code I can put on these hiking forms to prevent them from submitting when the enter key is pressed inadvertently when a user moves from one field to the next.

Thank you.

Coordinator
Dec 25, 2010 at 6:51 PM

Yes, there is.  After the <asp:Content> tag begins towards the top of the ASPX page, you can add this JS:

<script type="text/javascript">

    $(function () {
        $('input, select').keypress(function (e) {
            if (e.keyCode == 13) {
                return false;
            }
        });
    });

</script> 

Dec 26, 2010 at 3:43 AM

Thank you very much once again Ben.