Sup De,
I created an email generic subscription user control that I wanted to add to my website. Creating this user control would allow me to use it anywhere on my site. I was concerned about the Form Tags that already existed on the Mother Page (Default.aspx).
Note: You can't have 2 server form tags on one page anyway.
Here is my old html form. I stripped all the other tags for clarity.
<form name="newsletter" action="http://localhost/Funkysite/webmodules/MailingLists/Subscribe.aspx" method="get" ID="Form1">
<input type="hidden" name="ListId" value="14" ID="Hidden1">
<table ID="Table1">
<tr>
<td colspan="2">
First Name:
</td>
</tr>
<tr>
<td colspan="2">
<input type="text" name="FirstName" size="30" ID="Text1">
</td>
</tr>
<tr>
<td colspan="2">
Last Name:
</td>
</tr>
<tr>
<td colspan="2">
<input type="text" name="LastName" size="30" ID="Text2">
</td>
</tr>
<tr><td>
Email Address:</td></tr>
<tr>
<td><input type="text" name="Email" size="20" ID="Text3"></td>
<td><input type="submit" value="Submit" ID="Submit1" NAME="Submit1"></td>
</tr>
<tr>
<td colspan="2">
<input type="radio" name="Action" value="Subscribe" checked ID="Radio1">Subscribe
<input type="radio" name="Action" value="Unsubscribe" ID="Radio2">Unsubscribe
</td>
</tr>
</table>
</form
Here's the new code as a User Control.
I replaced all the html controls with server controls. Note the runat="server" for each control.
<table height="*" cellSpacing="0" cellPadding="0" width="100" border="0">
<tr>
<td class="subscribe">First Name:
</td>
</tr>
<tr>
<td><asp:textbox id="FirstName" Runat="server"></asp:textbox></td>
</tr>
<tr>
<td class="subscribe">Last Name:
</td>
</tr>
<tr>
<td><asp:textbox id="LastName" Runat="server"></asp:textbox></td>
</tr>
<tr>
<td class="subscribe">Email Address:
</td>
</tr>
<tr>
<td><asp:textbox id="Email" Runat="server"></asp:textbox></td>
</tr>
<tr>
<td class="subscribe">
<asp:radiobutton id="subscribe" runat="server" Text="Subscribe"
GroupName="Action" Checked="True"></asp:radiobutton><BR>
<asp:radiobutton id="unsubscribe" runat="server"
Text="Unsubscribe" GroupName="Action"></asp:radiobutton></td>
</tr>
<tr>
<td><br>
<asp:button id="submit" onclick="onsubmit_click"
runat="server" Text="Submit" cssclass="button"></asp:button></td>
</tr>
</table>
<b>Here is the
VB. Code behind that took the place of the GET METHOD AND ACTION of the old html form: <b>
Sub onSubmit_click( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles submit.Click
Dim Fname As String
Fname = FirstName.Text
Dim Lname As String
Lname = LastName.Text
Dim Mail As String
Mail = Email.Text
Dim Subchoice As String
If subscribe.Checked Then
Subchoice = "Subcribe"
Else : Subchoice = "Unsubscribe"
End If
Response.Redirect(("~/webmodules/Mailinglists/Subscribe.aspx?ListId=17&FirstName=" & Fname & "&LastName=" & Lname & "&Email=" & Mail & "&Action=" & Subchoice))
End Sub
The tricky part is the response.redirect string.
Disclaimer: I forgot to spell check. he he
I also hard coded the ListID in the redirect string. If the ListID is not a security issue, you can store it in a hidden server control for easy access. I just choose not to use a hidden control per my requirements.
De, don't forget the books that I suggested on my other post.