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 @ 02:37
    Chris
    0

    ascx and ascx.cs control

    After trying for hours, I cannot get this to work.

    I am trying to create a contact form that I had in a hard coded site to umbraco user control.  Using 4.5.x. In VS, I have target framework of 3.5.

     

    Here is my code:

     

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

    <div>
    <asp:PlaceHolder ID="formPH" runat="server" Visible="true">

    <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># </asp:ListItem>
    <asp:ListItem>#</asp:ListItem>
    <asp:ListItem># </asp:ListItem>
    <asp:ListItem># </asp:ListItem>
    <asp:ListItem># </asp:ListItem>
    <asp:ListItem># </asp:ListItem>
    <asp:ListItem># </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>

    </asp:PlaceHolder>
    <asp:PlaceHolder ID="successPH" runat="server" Visible="false">
    <p class="thankyou" style="color:green">Thank you for your contacting us. 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>


     

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


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

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

    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.mail.com";
    smtp.Send(mail);
    formPH.Visible = false;
    successPH.Visible = true;
    }
    catch
    {
    failPH.Visible = true;
    formPH.Visible = false;
    }
    }
    }
    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; }
    }
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 22, 2011 @ 03:10
    Tom Fulton
    0

    Hi Chris,

    What exactly is the problem?  Is the control showing up?  Are you getting an error message, and before or after you click Submit?

    One common issue, if everything shows up but nothing happens when you click submit, make sure the macro is wrapped in a <form runat="server"> tag in your template.

    Let us know the issue and I'm sure we can help get it straightened out!

    -Tom

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

    I put my ascx page in the usercontrols folder and the ascx.cs file in the app_code.

     

     

    I get this error when Iclick "Browse Properties".  On the site, I get:

     

    Program Signup or Request More Information is seperate <h1> tag.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 22, 2011 @ 03:48
    Tom Fulton
    0

    Just off the top of my head, the Inherits attribute in the directive is ".usercontrol.contactus" but the class in the codebehind is "contactus".  Have you changed these?  Maybe try dropping the ".usercontrol." from the Inherits?  Have you also copied the .dll file to /bin?

    If not I'll take a look when I'm around VS tomorrow :)

    -Tom

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

    Hey, Tom:

     

    Thanks for looking at this for me.  I never created a dll for the form.  I did change ".usercontrol.contactus" to "contactform.usercontrols.contactus".  Does this help?

    Again, appreciate it!

    Chris.

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

    I also get this is VS:

     

     

    saying: Error    Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).  

     

    (still trying to learn).

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 22, 2011 @ 04:11
    Tom Fulton
    0

    If you changed  to contactform.usercontrols.contactus, I believe you should change in your codebehind to match also, to public partial class contactform.usercontrols.contactus

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

    Doesn't seem to be doing it tom..... hmmm

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

    So it looks like I have it up and working.  Everything looks great (the reset button works, the balidation works) but it won't actually send the email or post back either a success or an error.....

  • Pasang Tamang 258 posts 458 karma points
    Mar 22, 2011 @ 05:53
    Pasang Tamang
    0

    I checked your code. Validation and reset button works but while sending mail it won't send. Again I tried by removing

    if (!IsValid) { return; }

    Now I got error. So may be Isvalid is creating problem in your code.

    Pnima

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

    Hi, Pnima:

    Thanks for looking at that.  I thought that was the problem as well.  It is not a problem when hard-coding, however, when creating the macro, Umbraco selects it as a Property as Boolean.

     

    Don't know much about it or why it is causing it.....

  • Pasang Tamang 258 posts 458 karma points
    Mar 22, 2011 @ 06:29
    Pasang Tamang
    0

    Hi Chris

    I have tried in umbraco also by setting IsValid's value=1 and it's showing error message to me. Error is due to smtp host. Is the IsValid's value 1 in your code? like "<umbraco:Macro IsValid="1" Alias="ContactForm1" runat="server"></umbraco:Macro>"

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

    Hi, Pasang:

     

    I tried that it and it doesnt seemt to have an effect.

     

    Chris.

Please Sign in or register to post replies

Write your reply to:

Draft