There is a way to send all input control values ​​to asp.net

I am looking for a way to submit all values ​​entered by a user into a form. Does this exist in asp.net?

here is my email code:

 Dim messagemain As String = emailbody
        Dim message As New MailMessage()
        message.IsBodyHtml = True
        message.From = New MailAddress("foo@foo.com")
        message.To.Add(New MailAddress("foo@foo.com"))
        message.Subject = ("Response from form")
        message.Body = (messagemain)
        Dim client As New SmtpClient()
        client.Host = "email.foo.foo"
        client.Send(message)

Usually I look through manually and declare everything necessary for email var, then send, but in this form more than 200 fields.

Thank.

+3
source share
2 answers

You can try to focus too much on the Controlspage collection , and if you find a text box, add its value to the body of the message:

var body = new StringBuilder();
foreach (var control in pageInstance.Controls)
{
    if (control is TextBox)
    {
        var value = ((TextBox)control).Text;
        body.AppendFormat("value: {0}<br/>", HttpUtility.HtmlEncode(value));
    }
}
message.Body = body.ToString();

. , , , ,... , , .

+4

, , , , .

var sb = new StringBuilder();
foreach (string key in this.Request.Form.Keys)
    sb.AppendFormat("{0} = {1}<br/>", key, this.Request.Form[key]);
var emailbody = sb.ToString();
+2

Source: https://habr.com/ru/post/1733491/


All Articles