如何引用HTML< textarea>的输入.控制在代码背后? [英] How do I reference the input of an HTML <textarea> control in codebehind?

查看:67
本文介绍了如何引用HTML< textarea>的输入.控制在代码背后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用textarea控件来允许用户输入文本,然后将其放入电子邮件正文中.在后面的代码中,引用用户输入的语法是什么?我以为我可以只使用message.Body = test123.Text;,但是无法识别.

I'm using a textarea control to allow the user to input text and then place that text into the body of an e-mail. In the code behind, what is the syntax for referencing the users input? I thought I could just use message.Body = test123.Text; but this is not recognized.

HTML:

<textarea id="TextArea1" cols="20" rows="2" ></textarea>

CodeBehind:

CodeBehind:

foreach (string recipient in recipients)
{         
  var message = new System.Net.Mail.MailMessage("sender@example.com", recipient);
  message.Subject = "Hello World!";         
  message.Body = test123.Text;                
  client.Send(message); 
} 

推荐答案

您没有在文本区域中使用.NET控件.将runat="server"添加到HTML TextArea控件或使用.NET控件:

You are not using a .NET control for your text area. Either add runat="server" to the HTML TextArea control or use a .NET control:

尝试一下:

<asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" />

然后在您的代码后面引用它:

Then reference it in your codebehind:

message.Body = TextArea1.Text;

这篇关于如何引用HTML&lt; textarea&gt;的输入.控制在代码背后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆