Subscribe form in asp.net

Hi, I'm trying to add a subscribe form to an asp.net page. I found what looks like an elegant solution in this post from 3 years ago! -> http://www.campaignmonitor.com/forums/viewtopic.php?id=839

Now I'm not a programmer but always willing to have a go - I need help implementing EllenD's solution in the above post but in C#!

I have 2 textboxes on the asp.net page TextBox1 (for Name) and TextBox2 (for Email) - what should my button_click event look like in the code behind?

Without knowing what I'm doing this is what I tried and surprise surprise...it doesn't work :) (ignorance is terrible thing!)  Any help appreciated. Cheers.

I tried:

protected void Button1_Click(object sender, EventArgs e)
    {
        string name = null;
        string email = null;

        name = Server.UrlEncode(TextBox1.Text);
        email = Server.UrlEncode(TextBox2.Text);

        Response.Redirect("http://my.pressissue.com/t/r/s/vlidrl/?cm-vlidrl-vlidrl =" + email + "cm-name" + name);

    }

pressissue, 5 years ago

OK here comes a one-man thread: Using default email and Name fields (haven't tried it with custom fields yet!)

Solution in C#:

<!-- in .aspx or .ascx page ->
place 2 textboxes on the page TextBox1 (for Name) and TextBox2 (for Email) and one button control:

<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:Button CssClass=" [your CSS class here]" ID="Button1" runat="server" Text="Sign Me Up!" onclick="Button1_Click" />

<!-- in code-behind file .ascx.cs -->

protected void Button1_Click(object sender, EventArgs e)
    {
        string name = null;
        string email = null;

        name = Server.UrlEncode(TextBox1.Text);
        email = Server.UrlEncode(TextBox2.Text);

        Response.Redirect("http://my.pressissue.com/t/r/s/vlidrl/?cm-vlidrl-vlidrl=" + email + "&cm-name=" + name);   

    }

NOTE: change the [ http://my.pressissue.com/t/r/s/vlidrl/ ] to whatever url is generated for you in your html form code - in the bit that reads <form action="[you url]" method="post" id="subForm">

Better than messing about with iFrames etc.

Kudos to EllenD for the original solution in VB...NICE!

pressissue, 5 years ago

Just noticed I made a typo above:

2nd textbox should be:

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

ALSO JUST TO SHARE:
There's an even more elegant solution but it is dependent on what else you've got going on inside your page:

[assuming your placing your form within asp.net <form runat:server> tags]
You can take your generated form code as is and just strip the <form> start and end tags. Replace the button with a .NET button and put your original <form action url> as postbackurl ="your URL" in the button tag>

This is by far the sweetest solution if it works for you. It didn't work for me as it rendered 'add to cart' buttons on my product pages useless! Everywhere else it was sweet. Just add one button + add the postbackURL!

EllenD's solution was the next best thing...simple & elegant!

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098