我有一个 asp.net 页面,我想将文本加载到 aspx 页面中的 textArea 控件中,并将其加载到代码隐藏 (C#) 中的一个变量中:
代码隐藏:
System.Web.UI.HtmlControls.HtmlTextArea Output1 =
(System.Web.UI.HtmlControls.HtmlTextArea)(FindControl("textarea1"));
Output1.Value = Output.ToString();
ASP:
<div style ="width: 78%; float: right; height: 85px; display: block;"
class="message_text_box_left">
<textarea id="textarea1" name="textarea1" cols="30" rows="3"
class="message_text_box" title="Share your Idias here..."
tabindex="1" onkeyup="addrow_fun();"></textarea>
</div>
但是它给出了这样的错误
Object reference not set to an instance of an object.
最佳答案
你应该添加
runat="server"
属性到文本区域。
或者,您最好使用 TextBox
ASP.NET control并设置 TextMode
property到 TextBoxMode.MultiLine
。示例如下:
代码隐藏:
Output1.Text = Output.ToString();
ASP:
<div style ="width: 78%; float: right; height: 85px; display: block;"
class="message_text_box_left">
<asp:TextBox ID="Output1" Rows="3"
CssClass="message_text_box" ToolTip="Share your ideas here..."
TextMode="MultiLine" />
</div>
关于c# - 使用 C# 从 asp.net 中的代码后面将文本加载到 textarea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9495428/