Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris 49 posts 67 karma points
    Mar 22, 2011 @ 15:58
    Chris
    0

    Problem with converted ascx contact form user control (IsValid probably causing).

    I have successfully (well almost) converted my aspx and aspx.cs contact form to a ascx contact form with .dll file.  However, I seem to be having an issue with the form actually submiitting.  It does validate the fields and the reset button works, however, the email form does not send.  I think it has to do with the IsValid property.

     

    Please take a look at code below.

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="contact.ascx.cs" Inherits="APTContact.contact" %>

    <div>
    <asp:PlaceHolder ID="formPH" runat="server" Visible="true">
    <form id="form1" runat="server">
    <table id="contact" cellspacing="5">

    <tr>
    <td class="name" >First Name:</td>
    <td style="width: 255px"> <asp:TextBox CssClass="field" ID="FNameTB" runat="server" /></td>
    </tr>
    <tr>
    <td colspan="2" style="width: 271px"> <asp:RequiredFieldValidator CssClass="validator" ID="reqFName" runat="server" ControlToValidate="FNameTB" ErrorMessage=" First Name Is Required" Display="Dynamic" />
    </td>
    </tr>

    <tr>
    <td class="name" style="width: 155px">Last Name:</td>
    <td style="width: 255px"> <asp:TextBox CssClass="field" ID="LNameTB" runat="server" /></td>
    </tr>
    <tr>
    <td colspan="2" style="width: 271px"> <asp:RequiredFieldValidator CssClass="validator" ID="reqLName" runat="server" ControlToValidate="LNameTB" ErrorMessage="Last Name Is Required" Display="Dynamic" />
    </td>
    </tr>

    <tr>
    <td class="name" style="width: 160px">Designation/Specialty: </td>
    <td style="width: 250px"> <asp:TextBox CssClass="field" ID="DSTB" runat="server" /></td>
    </tr>

    <tr>
    <td class="name">Medical License Registration Number: </td>
    <td style="width: 250px"> <asp:TextBox CssClass="field" ID="CPSOTB" runat="server" /></td>
    </tr>
    <tr>
    <td colspan="2" style="width: 271px"> <asp:RequiredFieldValidator CssClass="validator" ID="reqCPSOTB" runat="server" ControlToValidate="CPSOTB" ErrorMessage="This Is Required" Display="Dynamic" />
    </td>
    </tr>

    <tr>
    <td class="name" style="width: 155px">Email:</td>
    <td style="width: 255px">
    <asp:TextBox CssClass="field" ID="EmailTB" runat="server" /></td>
    </tr>
    <tr>
    <td colspan="2" style="width: 200px">
    <asp:RequiredFieldValidator CssClass="validator" ID="reqEmail" runat="server" ControlToValidate="EmailTB" ErrorMessage="Email Is Required" Display="Dynamic" />
    </td>
    </tr>

    <tr>
    <td class="name" style="width: 160px">Cell Number: </td>
    <td style="width: 250px"> <asp:TextBox CssClass="field" ID="PhoneTB" runat="server" /></td>

    </tr>
    <tr>
    <td colspan="2" style="width: 200px">
    <asp:RequiredFieldValidator CssClass="validator" ID="RequiredFieldValidator1" runat="server" ControlToValidate="PhoneTB" ErrorMessage="Cell Number Is Required" Display="Dynamic" />
    </td>
    </tr>

    <tr>
    <td class="name" style="width: 160px">I am Inquiring About: </td>
    <td style="width: 250px"> <asp:DropDownList CssClass="field" runat="server" ID="InquireList" >

    <asp:ListItem>Please Select One</asp:ListItem>
    <asp:ListItem>Attending a Group Program</asp:ListItem>
    <asp:ListItem>Customized 1 on 1 Training </asp:ListItem>
    <asp:ListItem>Pricing</asp:ListItem>
    <asp:ListItem>Customized Individual/Group Training</asp:ListItem>
    <asp:ListItem>Nearby Accommodations Offering Corporate Rates</asp:ListItem>
    <asp:ListItem>Other </asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>

    <tr>
    <td class="name" style="width: 160px">My Injection Experience Level Is: </td>
    <td style="width: 250px"> <asp:DropDownList CssClass="field" runat="server" ID="GaugeList" >

    <asp:ListItem>Please Select One</asp:ListItem>
    <asp:ListItem>I have had no cosmetic injection training </asp:ListItem>
    <asp:ListItem>I have been injecting Botox for less than 6 months </asp:ListItem>
    <asp:ListItem>I have been injecting Botox for more than 6 months </asp:ListItem>
    <asp:ListItem>I have been injecting Filler for less than 6 months </asp:ListItem>
    <asp:ListItem>I have been injecting Filler for more than 6 months </asp:ListItem>
    <asp:ListItem>I have been injecting Botox and Filler for less than 6 months </asp:ListItem>
    <asp:ListItem>I have been injecting Botox and Filler for more than 6 months </asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>

    <tr>
    <td class="name" >I Heard About APT Training Through: </td>
    <td style="width: 250px"> <asp:DropDownList CssClass="field" runat="server" ID="HeardList" >

    <asp:ListItem>Please Select One</asp:ListItem>
    <asp:ListItem>IAPAM</asp:ListItem>
    <asp:ListItem>Internet</asp:ListItem>
    <asp:ListItem>I have previously attended APT Training</asp:ListItem>
    <asp:ListItem>Referred/Other </asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>
    <tr>
    <td class="name" style="width: 160px">Referred/Other: </td>
    <td style="width: 250px"> <asp:TextBox CssClass="field" ID="ReferTB" runat="server" /></td>

    </tr>


    <tr>
    <td class="name" style="width: 155px">Comments:</td>
    <td style="width: 255px">
    <asp:TextBox CssClass="field" ID="CommentsTB" runat="server" TextMode="MultiLine" Width="200px" Height="80px" />
    </td>
    </tr>
    <tr>
    <td colspan="2" style="padding-left:220px; padding-top:20px">
    <asp:Button CssClass="submit2" ID="btnSubmit" runat="server" Text="Submit"
    Width="70px" OnClick="SendMail" OnClientClick="_gaq.push(['_trackEvent', 'Website Homepage','Contact Form', 'Submit']);"/>
    <asp:Button CssClass="reset" ID="btnReset" runat="server" Text="Reset" Width="63px"
    OnClick="Reset" OnClientClick=" _gaq.push(['_trackEvent', 'Website Homepage','Contact Form', 'Reset']);"/>
    </td>
    </tr>
    </table>
    </form>
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="successPH" runat="server" Visible="false">
    <p class="thankyou" style="color:green">Thank you for your contacting APT Training & Consulting. We have
    recieved your message and will get back to you shortly.</p>
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="failPH" runat="server" Visible="false">
    <p style="color:red">Sorry, there was an error. Please try again. If it happens
    again, please send us an email.</p>

    </asp:PlaceHolder>

    </div>



       

     

    and

     

    using System;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Net.Mail;

    namespace APTContact
    {
    public partial class contact : System.Web.UI.UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void SendMail(object sender, EventArgs e)
    {
    if (!IsValid)
    {
    return;
    }
    else
    {

    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(EmailTB.Text);
    mail.To.Add("[email protected]");
    mail.Subject = "APT Website Training Request";
    mail.IsBodyHtml = true;
    mail.Body += "First Name: " + FNameTB.Text + "<br /><br />";
    mail.Body += "Last Name: " + LNameTB.Text + "<br /><br />";
    mail.Body += "Designation/Specialty: " + DSTB.Text + "<br /><br />";
    mail.Body += "Medical License Registration Number: " + CPSOTB.Text + "<br /><br />";
    mail.Body += "Email: " + EmailTB.Text + "<br /><br />";
    mail.Body += "Phone Number: " + PhoneTB.Text + "<br /><br />";
    mail.Body += "Inquiring About: " + InquireList.SelectedValue + "<br /><br />";
    mail.Body += "Injection Experience: " + GaugeList.SelectedValue + "<br /><br />";
    mail.Body += "Heard About APT Through: " + HeardList.SelectedValue + "<br /><br />";
    mail.Body += "Heard About APT by Other/Referral: " + ReferTB.Text + "<br /><br />";
    mail.Body += "Comments: " + CommentsTB.Text + "<br /><br />";

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "mail.chris.ca";
    smtp.Send(mail);
    formPH.Visible = false;
    successPH.Visible = true;
    }

    }

    protected void Reset(object sender, EventArgs e)
    {
    FNameTB.Text = "";
    LNameTB.Text = "";
    DSTB.Text = "";
    CPSOTB.Text = "";
    EmailTB.Text = "";
    PhoneTB.Text = "";
    ReferTB.Text = "";
    CommentsTB.Text = "";

    }



    public bool IsValid { get; set; }
    }
    }

     

    and in the macro I get:

     

     

    Thanks,

     

    Chris.

  • kows 81 posts 151 karma points c-trib
    Mar 22, 2011 @ 16:59
    kows
    0

    if you have it like that,

    your isvalid will be false.

    Add the property to the macro and set its value or remove it.

    What's the use of it?

  • Chris 49 posts 67 karma points
    Mar 22, 2011 @ 17:17
    Chris
    0

    I am still learning C# and umbraco etc.  I thought it was necessary for the confirmation or error codes to appear.  It was originally an aspx and aspx.cs form.

    I don't want the Choose properties field to be checked but I cannot seem to change it.  What can I change in my ascx.cs file (or where ever)  to avoid this? The form works hard-coded, I don't know what to change.

     

    Thanks, kows for the reply.

     

    Chris.

     

     

  • kows 81 posts 151 karma points c-trib
    Mar 24, 2011 @ 14:40
    kows
    0

    if you drop  public bool IsValid { get; set; }

    the property wont show up anymore.

     

    drop the following to make the form work:

          if (!IsValid)

                {
                    return;
                }
                else
                {

    (in between stays)

         }

  • Chris 49 posts 67 karma points
    Mar 24, 2011 @ 14:53
    Chris
    0

    Thanks, Kows:

     

    I ended up creating a new form , but it was the !IsValid property.

     

    Thanks,

     

    Chris.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies