cancel
Showing results for 
Search instead for 
Did you mean: 
Due to an issue with YouTube, inserting videos in your emails is showing an error. Until they are able to resolve this issue, we recommend using a different video hosting service. We will continue to monitor this outage and update you as we have more information.

ASP.NET and Constant Contact

Occasional Participant

ASP.NET and Constant Contact

Since I am using ASP.NET I cannot use the example code that our marketing team wants to use to sign people for our newsletter that is hosted here. The form tag in the code prevents the rest of our code from working because you can only have a single form element on a page. Are there examples of signing people up for a newsletter using ASP.NET?

8 REPLIES 8
Moderator

Since you are using ASP.NET,

Since you are using ASP.NET, you can code your form in Visual Studio and have the submit button call a function in the corresponding .cs or .vb file.  We have posted sample code for the various API functions for C#.net.  This code is easily converted to Visual Basic if that's your prefered language.


 


Please let me know if you have any further questions on this.  You can find the sample C#.NET code here.

Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

Close...but no cigar...

I got a control to work that is basically the same as the code given to me by our marketing team from your site. Here is the control I created...(see problem below)...


 


 


 


 


 


 The problem is that I am using a Content Management System that does not support the PostBackUrl property. It breaks their editor (Site Finity). So I tried to remove the use of the PostBackUrl and create this control using a server side Click event handler and using Response.Redirect("http://visitor.constantcontact.com/d.jsp"); but that did not work as the Constant Contact page came up with errors. Any ideas??


 


 


<%


@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsletterSignup.ascx.cs" Inherits="NewsletterSignup" %> h2>

</


<


h2>p>

Submit your email to receive our monthly newsletter dedicated to career and recruiting


related topics.



</


<


p>div style="text-align: left;">

 


<div style="width: 226px; height: 70px;">

 


 


<span style="background-color: #006699; margin-top: 2px; float: left; margin-left: 2px;margin-right: 2px;">

 


 


<img alt="" style="border-bottom: 0px solid; border-left: 0px solid; border-top: 0px solid;border-right: 0px solid;" src="http://img.constantcontact.com/ui/images1/visitor/email1_trans.gif" /></span><input

 


 


style="border-bottom: #999999 1px solid; border-left: #999999 1px solid; font-family: verdana,geneva,arial,helvetica,sans-serif;border-top: #999999 1px solid; border-right: #999999 1px solid;" type="text"

 


name="ea" />

 


<asp:Button ID="Submit" runat="server" PostBackUrl="http://visitor.constantcontact.com/d.jsp"

 


Style="font-family: verdana,arial,helvetica,sans-serif; font-size: 10px;" Text="GO">

 


</asp:Button><br />

 


<input value="1100358239499" type="hidden" name="m" />

 


<input value="oi" type="hidden" name="p" />

 


</


</div>div>

 


 


 


 


<



Subscribe to Leadership Matters

Moderator

While this is actually not an

While this is actually not an API question, I was able to change some of your code and it works fine for me.  I was able to get to your customized Join My Mailing List form using this code:


 


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div style="text-align: left;">

        <div style="width: 226px; height: 70px;">

            <span style="background-color: #006699; margin-top: 2px; float: left; margin-left: 2px;

                margin-right: 2px;">

                <img alt="" style="border-bottom: 0px solid; border-left: 0px solid; border-top: 0px solid;

                    border-right: 0px solid;" src="http://img.constantcontact.com/ui/images1/visitor/email1_trans.gif" />

            </span>

            <input style="border-bottom: #999999 1px solid; border-left: #999999 1px solid; font-family: verdana,geneva,arial,helvetica,sans-serif;

                border-top: #999999 1px solid; border-right: #999999 1px solid;" type="text"

                name="ea" />

            <asp:Button ID="Submit" runat="server" PostBackUrl="http://visitor.constantcontact.com/d.jsp"

                Style="font-family: verdana,arial,helvetica,sans-serif; font-size: 10px;" Text="GO">

            </asp:Button><br />

            <input value="1100358239499" type="hidden" name="m" />

            <input value="oi" type="hidden" name="p" />

        </div>

    </div>

    </form>

</body>

</html>

Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

Thanks for looking at

Thanks for looking at this...yea THAT code works...I have that in my ASP.NET control. Unfortunately I cannot use the PostBackUrl property. Our CMS does not allow controls that use this property in their pages as it causes editor problems. Any other ideas of a solution. I just need something I can use like this that will enable users to add themselves to the list in Constant Contact.


I tried removing the PostBackUrl property and using an OnClick event handler and calling Response.Redirect to the JSP page...but no luck. Its not sending back the hidden input tags I am guessing.

Moderator

This code should help you out

This code should help you out with this problem:


 


.aspx Code:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div style="text-align: left;">

        <div style="width: 226px; height: 70px;">

            <span style="background-color: #006699; margin-top: 2px; float: left; margin-left: 2px;

                margin-right: 2px;">

                <img alt="" style="border-bottom: 0px solid; border-left: 0px solid; border-top: 0px solid;

                    border-right: 0px solid;" src="http://img.constantcontact.com/ui/images1/visitor/email1_trans.gif" />

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

            </span>

            &nbsp;<asp:Button ID="Submit" runat="server"

                Style="font-family: verdana,arial,helvetica,sans-serif; font-size: 10px;"

                Text="GO" onclick="Submit_Click">

            </asp:Button><br />

        </div>

    </div>

    </form>

</body>

</html>


 


.aspx.cs Code:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;



public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {



    }

    protected void Submit_Click(object sender, EventArgs e)

    {

        // Add Validation Code for Email address



        // If Valid, redirect to the JSP and create the proper URI

        Response.Redirect("http://visitor.constantcontact.com/d.jsp?m=1100358239499&p=oi&ea=" + TextBox1.Text);

    }

}


 

Dave Berard
Senior Product Manager, Constant Contact
Tags (2)
Highlighted
Occasional Participant

Outstanding!

Outstanding!

Re: This code should help you out

I'm new to VB .Net (but have been creating html websites for years) and am trying to navigate the Constant Contact and VB .Net maze simultaneously.  I've learned you can't have a form within a form so the CC button generator doesn't work.  I need to have code beind the submit button.  I've been trying to work with my project and the examples here but now receive compile errors.  Is there a complete code example that I can use as a template?  I appreciate your time.

CTCT Employee

Re: This code should help you out

Hi,

 

Our all-inclusive contact signup forms in ASP.NET are located at this link.  Some sample code in VB that lives behind the submit button using our wrapper could look something like this:

 

       Dim authData = New AuthenticationData(apiKey, Username, Password)        

        'add/update contact example
        Dim contactoptinlist As New ContactOptInList
        contactoptinlist.ContactList = New ContactList(1)

        Dim emailaddress As String() = New String() {"test_02072013@test.com"}
        Dim nextchunkid As String
        Dim search As IList(Of Contact) = Utility.SearchContactByEmail(authData, emailaddress, nextchunkid)

        If search.Count > 0 Then
            Dim contact As New Contact()
            contact.Id = search(0).Id
            contact.Link = search(0).Link
            contact = Utility.GetContactDetailsById(authData, contact.Id)
            contact.FirstName = "some name"
            contact.LastName = "some name"
            contact.OptInSource = ContactOptSource.ActionByContact
            contact.ContactLists.Add(contactoptinlist)
            Utility.UpdateContactFullForm(authData, contact)

        Else
            Dim contact As New Contact()
            contact.FirstName = "some name"
            contact.LastName = "some name"
            contact.EmailAddress = "test_02072013@test.com"
            contact.OptInSource = ContactOptSource.ActionByContact
            contact.ContactLists.Add(contactoptinlist)
            Utility.CreateNewContact(authData, contact)
        End If

 

I'm not sure if you might be more comfortable with it, but I also have code samples in PHP, particularly a light signup form you could use. Let me know if that would be more helpful.

 

Best Regards,

Shannon W.

API Support Specialist