[英]How do I reference the input of an HTML <textarea> control in codebehind?
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.我正在使用 textarea 控件来允许用户输入文本,然后将该文本放入电子邮件正文中。 In the code behind, what is the syntax for referencing the users input?在后面的代码中,引用用户输入的语法是什么? I thought I could just use message.Body = test123.Text;
我以为我可以只使用message.Body = test123.Text;
but this is not recognized.但这不被承认。
HTML: HTML:
<textarea id="TextArea1" cols="20" rows="2" ></textarea>
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);
}
You are not using a .NET control for your text area.您的文本区域没有使用 .NET 控件。 Either add runat="server"
to the HTML TextArea control or use a .NET control:将runat="server"
添加到 HTML TextArea 控件或使用 .NET 控件:
Try this:试试这个:
<asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" />
Then reference it in your codebehind:然后在你的代码隐藏中引用它:
message.Body = TextArea1.Text;
You need to use runat="server"
like this:您需要像这样使用runat="server"
:
<textarea id="TextArea1" cols="20" rows="2" runat="server"></textarea>
You can use the runat=server attribute with any standard HTML element, and later use it from codebehind.您可以将 runat=server 属性与任何标准 HTML 元素一起使用,然后在代码隐藏中使用它。
First make sure you have the runat="server"
attribute in your textarea
tag like this首先确保您的textarea
标记中有runat="server"
属性,如下所示
<textarea id="TextArea1" cols="20" rows="2" runat="server"></textarea>
Then you can access the content via:然后您可以通过以下方式访问内容:
string body = TextArea1.value;
You should reference the textarea ID and include the runat="server"
attribute to the textarea
您应该引用 textarea ID 并将runat="server"
属性包含到textarea
message.Body = TextArea1.Text;
What is test123
?什么是test123
?
缺少属性runat="server"
或在代码中使用Request.Params["TextArea1"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.