I have a few large, specifically formatted to the customer's request, tables with input. It looks similar to the following...
<body id="Body" class="Window" runat="server">
<form id="Form" runat="server" defaultbutton="SubmitLinkButton">
<!-- Markup for a the SubmitLinkButton and DropDownList -->
<!-- to pick which Table is shown -->
<asp:Table ID="Table1" runat="server">
<asp:TableRow class="row" runat="server">
<asp:TableCell runat="server">
<pre> Some Input1 </pre>
<pre>___________________</pre>
<pre>|___<asp:Textbox ID="Textbox1" runat="server"></asp:Textbox>____|</pre>
<pre>|_________________|</pre>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Table ID="Table2" runat="server">
<asp:TableRow class="row" runat="server">
<asp:TableCell runat="server">
<pre> Some Input2 </pre>
<pre>___________________</pre>
<pre>|___<asp:Textbox ID="Textbox2" runat="server"></asp:Textbox>____|</pre>
<pre>|_________________|</pre>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
Underwhelming, right?
Only one of the four tables is visible or not depending on the selection chosen in the DropDownList. Each table has upwards of 30-40 inputs and each area with inputs is formatted uniquely. All formatted the same way (^^^like above^^^), but one may have a section with 3 inputs and lots of text or 8 inputs and little text or no inputs and just a section of text.
Hopefully all of that makes sense.
What I need to figure out is how to have the user be able to "Submit" the form via the SubmitLinkButton
which will send an email that looks identical to the form they filled out to a group of email addresses setup in the SystemFramwork.config
.
I've attempted to do this, using Visual Basic
, with RenderControl()
, but I kept getting errors saying my Textboxes needed to be inside a form with runat="server"
in it, and as you can see in my code above I have that. So, I'm not sure what was going on there.
Since the form is formatted so customized, If I can't somehow render the HTML form from page to email to have them look identical, I don't know any other option than to add the markup to the email manually, which just seems like a waste of time and making redundancies in the project.
Any insight would be greatly appreciated!
I'm still currently working with a pseudo solution that looks something like this...
Public Sub SubmitLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitLinkButton.Click
Dim result As String = vbNull
Dim stringWriter As New StringWriter()
Dim htmlWriter As New HtmlTextWriter(stringWriter)
'If the user selected something with the DropDown
If (DDL_Selection IsNot "")
Dim email As New MailMessage(FromConfigVar, ToConfigVar)
email.Subject = DDL_Selection.SelectedValue & " Table"
email.IsBodyHtml = True
Select Case DDL_Selection
Case "Table1"
Try
htmlWriter.RenderBeginTag(HtmlTextWriterTag.Table)
Table1.RenderControl(htmlWriter)
htmlWriter.RenderEndTag()
htmlWriter.Flush()
result = stringWriter.ToString()
Finally
htmlWriter.Close()
stringWriter.Close()
End Try
End Select
mailMessage.Body = result
Else
'Do nothing
End If
End Sub
Again, this solution is not working, nor do I think I'm even close to being on the right track. Just thought I'd show what I've tried.
I got this version working but did not get any user-input returned. This puts the html into an email; uses HtmlAgilityPack.
If you override the Page's VerifyRenderingInServerForm Method to not perform the validation that is causing the issue you can get around this problem: