Reputation: 27
I've one asp.net page and I want to load text into the textArea control which is in aspx page from into a variable in code behind (C#):
Code behind:
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>
but it is giving error like
Object reference not set to an instance of an object.
Upvotes: 1
Views: 18384
Reputation: 1
Add runat="server" and get value with InnerText from code behind
Upvotes: 0
Reputation: 11
Add runat="server"
in *.aspx
file. Use Innertext
property to set the text value.
E.g.
htmlTexarea.InnerHtml = "sample"
Upvotes: 1
Reputation: 40736
You should add the
runat="server"
attribute to the text area.
Or, preferable you should use the TextBox
ASP.NET control and set the TextMode
property to TextBoxMode.MultiLine
. Example follows:
Code behind:
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>
Upvotes: 3
Reputation: 8051
If you add the runat="server" attribute you should be able to use the textarea1.innerText directly.
Upvotes: 0
Reputation:
Try casting to HTML generic control and set it's value or change it to use an asp textbox textmode= multiline
Upvotes: 0
Reputation: 561
runat="server"
to your controltextarea
/textbox
declaration and fix it.FindControl
function (it is not recursive), get control by ID. textarea1.Value = xxx;
Upvotes: 0